Games::RailRoad::Node - a node object
Games::RailRoad::Node provides a node object. This is the base class for the following classes:
Games::RailRoad::Node
Games::RailRoad::Node::Half is a node with only one segment, from the center to one of the 8 extremities of a square.
Games::RailRoad::Node::Half
Games::RailRoad::Node::Straight is a node with two segments, linking two of the 8 extremities of a square.
Games::RailRoad::Node::Straight
Games::RailRoad::Node::Switch is a node with three segments, linking three of the 8 extremities of a square through the center. The active segment taken by a train riding this node can switch between two of the segments.
Games::RailRoad::Node::Switch
Games::RailRoad::Node::Cross is a node with four segments: two straight lines crossing in the center of the square.
Games::RailRoad::Node::Cross
Each of those classes also has subclasses, one for each configuration allowed. They are named after each of the existing extremity of the square linked (in uppercase), sorted and separated by underscore (_). For example: Games::RailRoad::Node::Switch::N_S_SE.
_
Games::RailRoad::Node::Switch::N_S_SE
Note that each segment coming out of a node belongs to 2 different (adjacent) nodes.
Create a new node object. One can pass a hash reference with the following keys:
the column of the canvas where the node is.
the row of the canvas where the node is.
Try to extend $node in the wanted $dir. Return undef if it isn't possible. In practice, note that the object will change of base class.
$node
$dir
$dir should be one of nw, n, ne, w, e, sw, s, se. Of course, other values are accepted but won't result in a node extension.
nw
n
ne
w
e
sw
s
se
Return true if $node can be connected to the wanted $dir. Return false otherwise.
$dir should be one of nw, n, ne, w, e, sw, s, se. Of course, other values are accepted but will return always false.
Return a list of dirs in which the node is connected.
Request $node to remove itself from $canvas.
$canvas
Request $node to draw itself on $canvas, assuming that each square has a length of $tilelen. Note that this method calls the delete() method first.
$tilelen
delete()
When $node is reached by a train, this method will return the next direction to head to, assuming the train was coming from $from.
$from
Note that the method can return undef if there's no such $from configured, or if the node is a dead-end.
Request a node to change its exit, if possible. This is a no-op for most nodes, except Games::Railroad::Node::Switch::*.
Games::Railroad::Node::Switch::*
Games::RailRoad.
Jerome Quelin, <jquelin at cpan.org>
<jquelin at cpan.org>
Copyright (c) 2008 Jerome Quelin, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Games::RailRoad, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Games::RailRoad
CPAN shell
perl -MCPAN -e shell install Games::RailRoad
For more information on module installation, please visit the detailed CPAN module installation guide.