Games::RailRoad::Node - a node object
version 1.101330
This module provides a node object. This is the base class for the following classes:
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::Straight is a node with two segments, linking two of the 8 extremities of a square.
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::Cross is a node with four segments: two straight lines crossing in the center of the square.
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.
_
Note that each segment coming out of a node belongs to 2 different (adjacent) nodes.
The node position (a Games::RailRoad::Vector).
Create a new node object. One can pass a hash reference with the available attributes.
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 always return 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::*
Jerome Quelin
This software is copyright (c) 2008 by Jerome Quelin.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system 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.