| 1 | # | ||
| 2 | # This file is part of Games-RailRoad | ||
| 3 | # | ||
| 4 | # This software is copyright (c) 2008 by Jerome Quelin. | ||
| 5 | # | ||
| 6 | # This is free software; you can redistribute it and/or modify it under | ||
| 7 | # the same terms as the Perl 5 programming language system itself. | ||
| 8 | # | ||
| 9 | 17 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 17 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 17 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | package Games::RailRoad::Node::Switch; | ||
| 14 | 17 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 17 | $Games::RailRoad::Node::Switch::VERSION = '1.101330'; | |
| 16 | } | ||
| 17 | # ABSTRACT: a node object with three branches | ||
| 18 | |||
| 19 | 17 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 17 | ▶ | use MooseX::Has::Sugar; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 17 | ▶ | use MooseX::SemiAffordanceAccessor; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | 17 | extends qw{ Games::RailRoad::Node }; | |
| 24 | |||
| 25 | 17 | ▶ | use Games::RailRoad::Vector; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 26 | |||
| 27 | |||
| 28 | # -- attributes | ||
| 29 | 17 | has _switch => ( rw, isa=>'Int' ); | |
| 30 | |||
| 31 | |||
| 32 | # -- public methods | ||
| 33 | |||
| 34 | 0 | ▶ | sub draw { |
|
Subroutine
draw: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 35 | 0 | my ($self, $canvas, $tilelen) = @_; | |
| 36 | 0 | $self->SUPER::draw($canvas, $tilelen); | |
| 37 | |||
| 38 | 0 | my $pos = $self->position; | |
| 39 | 0 | my $dir = $self->_sw_exits->[ $self->_switch ]; | |
| 40 | 0 | my $vec = Games::RailRoad::Vector->new_dir($dir); | |
| 41 | 0 | my $x = $tilelen * ( $pos->posx + $vec->posx / 3 ); | |
| 42 | 0 | my $y = $tilelen * ( $pos->posy + $vec->posy / 3 ); | |
| 43 | |||
| 44 | # add some fancy drawing | ||
| 45 | 0 | my $radius = 2; | |
| 46 | 0 | $canvas->createOval( | |
| 47 | $x-$radius, $y-$radius, | ||
| 48 | $x+$radius, $y+$radius, | ||
| 49 | -outline => 'green', | ||
| 50 | -tags => [ "$pos" ], | ||
| 51 | ); | ||
| 52 | |||
| 53 | } | ||
| 54 | |||
| 55 | 0 | ▶ | sub switch { |
|
Subroutine
switch: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 56 | 0 | my ($self) = @_; | |
| 57 | 0 | $self->_set_switch( ($self->_switch + 1) % 2 ); | |
| 58 | } | ||
| 59 | |||
| 60 | |||
| 61 | 17 | __PACKAGE__->meta->make_immutable; | |
| 62 | 17 | 1; | |
| 63 | |||
| 64 | |||
| 65 | =pod | ||
| 66 | |||
| 67 | =head1 NAME | ||
| 68 | |||
| 69 | Games::RailRoad::Node::Switch - a node object with three branches | ||
| 70 | |||
| 71 | =head1 VERSION | ||
| 72 | |||
| 73 | version 1.101330 | ||
| 74 | |||
| 75 | =head1 DESCRIPTION | ||
| 76 | |||
| 77 | This package is a virtual class representing a node object with three | ||
| 78 | branches. There is a switch, meaning one can change the exit associated | ||
| 79 | to a given end. | ||
| 80 | |||
| 81 | The following methods are implemented in this class: | ||
| 82 | |||
| 83 | =over 4 | ||
| 84 | |||
| 85 | =item * draw | ||
| 86 | |||
| 87 | =item * switch | ||
| 88 | |||
| 89 | =back | ||
| 90 | |||
| 91 | Refer to L<Games::RailRoad::Node> for a description of the various node | ||
| 92 | types and methods. | ||
| 93 | |||
| 94 | =head1 AUTHOR | ||
| 95 | |||
| 96 | Jerome Quelin | ||
| 97 | |||
| 98 | =head1 COPYRIGHT AND LICENSE | ||
| 99 | |||
| 100 | This software is copyright (c) 2008 by Jerome Quelin. | ||
| 101 | |||
| 102 | This is free software; you can redistribute it and/or modify it under | ||
| 103 | the same terms as the Perl 5 programming language system itself. | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | |||
| 108 | __END__ | ||