| 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 | 1 | ▶ | use 5.010; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 12 | |||
| 13 | package Games::RailRoad::Train; | ||
| 14 | 1 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 1 | $Games::RailRoad::Train::VERSION = '1.101330'; | |
| 16 | } | ||
| 17 | # ABSTRACT: a train object | ||
| 18 | |||
| 19 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 20 | 1 | ▶ | use MooseX::Has::Sugar; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 21 | 1 | ▶ | use MooseX::SemiAffordanceAccessor; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | 1 | ▶ | use Games::RailRoad::Types qw{ Num_0_1 }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 24 | |||
| 25 | |||
| 26 | # -- attributes | ||
| 27 | |||
| 28 | |||
| 29 | 1 | has from => ( rw, isa=>'Games::RailRoad::Vector' ); | |
| 30 | 1 | has to => ( rw, isa=>'Games::RailRoad::Vector' ); | |
| 31 | 1 | has frac => ( rw, isa=>Num_0_1 ); | |
| 32 | |||
| 33 | |||
| 34 | # -- constructor & initializers | ||
| 35 | |||
| 36 | |||
| 37 | # provided by moose | ||
| 38 | |||
| 39 | |||
| 40 | # -- public methods | ||
| 41 | |||
| 42 | |||
| 43 | 0 | ▶ | sub draw { |
|
Subroutine
draw: not called CC=1 SCAR=6.9
Pod
documented
| |||
| 44 | 0 | my ($self, $canvas, $tilelen) = @_; | |
| 45 | 0 | my $from = $self->from; | |
| 46 | 0 | my $to = $self->to; | |
| 47 | 0 | my $frac = $self->frac; | |
| 48 | |||
| 49 | 0 | my $diag = 2; | |
| 50 | 0 | my $colf = $from->posx; my $rowf = $from->posy; | |
| 51 | 0 | my $colt = $to->posx; my $rowt = $to->posy; | |
| 52 | 0 | $canvas->delete("$self"); | |
| 53 | 0 | my $x = ( $colf + ($colt-$colf) * $frac ) * $tilelen; | |
| 54 | 0 | my $y = ( $rowf + ($rowt-$rowf) * $frac ) * $tilelen; | |
| 55 | 0 | $canvas->createOval( | |
| 56 | $x - $diag, $y - $diag, | ||
| 57 | $x + $diag, $y + $diag, | ||
| 58 | -fill => 'blue', | ||
| 59 | -tags => [ "$self" ], | ||
| 60 | ); | ||
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | # -- private methods | ||
| 65 | |||
| 66 | |||
| 67 | 1 | 1; | |
| 68 | |||
| 69 | |||
| 70 | =pod | ||
| 71 | |||
| 72 | =head1 NAME | ||
| 73 | |||
| 74 | Games::RailRoad::Train - a train object | ||
| 75 | |||
| 76 | =head1 VERSION | ||
| 77 | |||
| 78 | version 1.101330 | ||
| 79 | |||
| 80 | =head1 DESCRIPTION | ||
| 81 | |||
| 82 | This class models a train object that moves on the rails. | ||
| 83 | |||
| 84 | =head1 ATTRIBUTES | ||
| 85 | |||
| 86 | =head2 from | ||
| 87 | |||
| 88 | The node from where the train is coming (a L<Games::RailRoad::Vector> object). | ||
| 89 | |||
| 90 | =head2 to | ||
| 91 | |||
| 92 | The node where the train is headed (a L<Games::RailRoad::Vector> object). | ||
| 93 | |||
| 94 | =head2 frac | ||
| 95 | |||
| 96 | A number between 0 and 1 indicating where exactly the train is between | ||
| 97 | its from and to nodes. | ||
| 98 | |||
| 99 | =head1 METHODS | ||
| 100 | |||
| 101 | =head2 my $train = Games::RailRoad::Train->new( \%opts ); | ||
| 102 | |||
| 103 | Create and return a new train object. One can pass a hash reference with | ||
| 104 | the available attributes. | ||
| 105 | |||
| 106 | =head2 $train->draw( $canvas, $tilelen ); | ||
| 107 | |||
| 108 | Request C<$train> to draw itself on C<$canvas>, assuming that each square | ||
| 109 | has a length of C<$tilelen>. | ||
| 110 | |||
| 111 | =head1 AUTHOR | ||
| 112 | |||
| 113 | Jerome Quelin | ||
| 114 | |||
| 115 | =head1 COPYRIGHT AND LICENSE | ||
| 116 | |||
| 117 | This software is copyright (c) 2008 by Jerome Quelin. | ||
| 118 | |||
| 119 | This is free software; you can redistribute it and/or modify it under | ||
| 120 | the same terms as the Perl 5 programming language system itself. | ||
| 121 | |||
| 122 | =cut | ||
| 123 | |||
| 124 | |||
| 125 | __END__ | ||