Jérôme Quelin
and 1 contributors

NAME

Games::RailRoad::Node - a node object

VERSION

version 1.101330

DESCRIPTION

This module 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.

ATTRIBUTES

position

The node position (a Games::RailRoad::Vector).

METHODS

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 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 always return 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::*.

AUTHOR

  Jerome Quelin

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.