Jerome Quelin > Games-RailRoad-1.00 > Games::RailRoad::Node

Download:
Games-RailRoad-1.00.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
Report a bug
Source  

NAME ^

Games::RailRoad::Node - a node object

DESCRIPTION ^

Games::RailRoad::Node provides a node object. This is the base class for the following classes:

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.

CONSTRUCTOR ^

my $node = Games::RailRoad::Node->new( \%opts );

Create a new node object. One can pass a hash reference with the following keys:

col => $col

the column of the canvas where the node is.

row => $row

the row of the canvas where the node is.

PUBLIC METHODS ^

$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 nw, n, ne, w, e, sw, s, 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 nw, n, ne, w, e, sw, s, se. Of course, other values are accepted but will return always false.

my @dirs = $node->connections;

Return a list of dirs in which the node is connected.

$node->delete( $canvas );

Request $node to remove itself from $canvas.

$node->draw( $canvas, $tilelen );

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.

my $to = $node->next_dir( $from );

When $node is reached by a train, this method will return the next direction to head to, assuming the train was coming from $from.

Note that the method can return undef if there's no such $from configured, or if the node is a dead-end.

$node->switch;

Request a node to change its exit, if possible. This is a no-op for most nodes, except Games::Railroad::Node::Switch::*.

SEE ALSO ^

Games::RailRoad.

AUTHOR ^

Jerome Quelin, <jquelin at cpan.org>

COPYRIGHT & LICENSE ^

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.