- COPYRIGHT AND LICENSE
Games::RailRoad::Node - a node object
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).
my $node = Games::RailRoad::Node->new( \%opts );
Create a new node object. One can pass a hash reference with the available attributes.
$node->connect( $dir );
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.
$dir should be one of
se. Of course, other values are accepted but won't result in a node extension.
$node->connectable( $dir );
Return true if
$node can be connected to the wanted
$dir. Return false otherwise.
$dir should be one of
se. Of course, other values are accepted but will always return false.
my @dirs = $node->connections;
Return a list of dirs in which the node is connected.
$node->delete( $canvas );
$node to remove itself from
$node->draw( $canvas, $tilelen );
$node to draw itself on
$canvas, assuming that each square has a length of
$tilelen. Note that this method calls the
delete() method first.
my $to = $node->next_dir( $from );
$node is reached by a train, this method will return the next direction to head to, assuming the train was coming 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
COPYRIGHT AND LICENSE
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.