line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
4
|
|
|
4
|
|
26
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
145
|
|
2
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
141
|
|
3
|
|
|
|
|
|
|
package Games::Board::Space 1.014; |
4
|
|
|
|
|
|
|
# ABSTRACT: a parent class for spaces on game board |
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
22
|
use Carp; |
|
4
|
|
|
|
|
16
|
|
|
4
|
|
|
|
|
2224
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
9
|
|
|
|
|
|
|
#pod |
10
|
|
|
|
|
|
|
#pod use Games::Board; |
11
|
|
|
|
|
|
|
#pod |
12
|
|
|
|
|
|
|
#pod my $board = Games::Board->new; |
13
|
|
|
|
|
|
|
#pod |
14
|
|
|
|
|
|
|
#pod $board->add_space(Games::Board::Space->new( |
15
|
|
|
|
|
|
|
#pod id => 'go', |
16
|
|
|
|
|
|
|
#pod dir => { next => 'mediterranean', prev => 'boardwalk' }, |
17
|
|
|
|
|
|
|
#pod cost => undef |
18
|
|
|
|
|
|
|
#pod )); |
19
|
|
|
|
|
|
|
#pod |
20
|
|
|
|
|
|
|
#pod my $tophat = Games::Board::Piece->new(id => 'tophat')->move(to => 'go'); |
21
|
|
|
|
|
|
|
#pod |
22
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
23
|
|
|
|
|
|
|
#pod |
24
|
|
|
|
|
|
|
#pod This module provides a base class for representing the spaces on a game board. |
25
|
|
|
|
|
|
|
#pod |
26
|
|
|
|
|
|
|
#pod =cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#pod =method new |
29
|
|
|
|
|
|
|
#pod |
30
|
|
|
|
|
|
|
#pod This method constructs a new space and returns it. |
31
|
|
|
|
|
|
|
#pod |
32
|
|
|
|
|
|
|
#pod =cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub new { |
35
|
196
|
|
|
196
|
1
|
284
|
my $class = shift; |
36
|
196
|
|
|
|
|
393
|
my %args = @_; |
37
|
|
|
|
|
|
|
|
38
|
196
|
50
|
|
|
|
366
|
return unless $args{id}; |
39
|
|
|
|
|
|
|
croak "no board supplied in space creation" |
40
|
196
|
50
|
|
|
|
255
|
unless eval { $args{board}->isa('Games::Board') }; |
|
196
|
|
|
|
|
525
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $space = { |
43
|
|
|
|
|
|
|
id => $args{id}, |
44
|
|
|
|
|
|
|
board => $args{board}, |
45
|
196
|
|
|
|
|
455
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$space->{dir} = $args{dir} |
48
|
196
|
100
|
66
|
|
|
510
|
if $args{dir} and (ref $args{dir} eq 'HASH'); |
49
|
|
|
|
|
|
|
|
50
|
196
|
|
|
|
|
548
|
bless $space => $class; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
#pod =method id |
54
|
|
|
|
|
|
|
#pod |
55
|
|
|
|
|
|
|
#pod This method returns the id of the space. |
56
|
|
|
|
|
|
|
#pod |
57
|
|
|
|
|
|
|
#pod =cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub id { |
60
|
246
|
|
|
246
|
1
|
336
|
my $space = shift; |
61
|
|
|
|
|
|
|
|
62
|
246
|
|
|
|
|
696
|
return $space->{id}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#pod =method board |
66
|
|
|
|
|
|
|
#pod |
67
|
|
|
|
|
|
|
#pod This method returns board on which this space sits. |
68
|
|
|
|
|
|
|
#pod |
69
|
|
|
|
|
|
|
#pod =cut |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub board { |
72
|
142
|
|
|
142
|
1
|
199
|
my $space = shift; |
73
|
142
|
|
|
|
|
307
|
$space->{board}; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
#pod =method dir_id |
77
|
|
|
|
|
|
|
#pod |
78
|
|
|
|
|
|
|
#pod my $id = $space->dir_id($dir); |
79
|
|
|
|
|
|
|
#pod |
80
|
|
|
|
|
|
|
#pod This method returns the id of the space found in the given direction from this |
81
|
|
|
|
|
|
|
#pod space. |
82
|
|
|
|
|
|
|
#pod |
83
|
|
|
|
|
|
|
#pod =cut |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub dir_id { |
86
|
28
|
|
|
28
|
1
|
68
|
my ($space, $dir) = @_; |
87
|
|
|
|
|
|
|
|
88
|
28
|
50
|
|
|
|
197
|
return $space->{dir}{$dir} if (ref $space->{dir} eq 'HASH'); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
#pod =method dir |
92
|
|
|
|
|
|
|
#pod |
93
|
|
|
|
|
|
|
#pod my $new_space = $space->dir($dir); |
94
|
|
|
|
|
|
|
#pod |
95
|
|
|
|
|
|
|
#pod This method returns the space found in the given direction from this space. |
96
|
|
|
|
|
|
|
#pod |
97
|
|
|
|
|
|
|
#pod =cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub dir { |
100
|
2
|
|
|
2
|
1
|
6
|
my ($space, $dir) = @_; |
101
|
2
|
|
|
|
|
7
|
$space->board->space($space->dir_id($dir)); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#pod =method contains |
105
|
|
|
|
|
|
|
#pod |
106
|
|
|
|
|
|
|
#pod my $bool = $space->contains($piece); |
107
|
|
|
|
|
|
|
#pod |
108
|
|
|
|
|
|
|
#pod This method returns a true value if the space contains the passed piece. |
109
|
|
|
|
|
|
|
#pod |
110
|
|
|
|
|
|
|
#pod =cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub contains { |
113
|
7
|
|
|
7
|
1
|
14
|
my ($self, $piece) = @_; |
114
|
7
|
100
|
|
|
|
10
|
return 1 if grep { $_ eq $piece->id } @{$self->{contents}}; |
|
2
|
|
|
|
|
7
|
|
|
7
|
|
|
|
|
32
|
|
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
#pod =method receive |
118
|
|
|
|
|
|
|
#pod |
119
|
|
|
|
|
|
|
#pod $space->receive($piece); |
120
|
|
|
|
|
|
|
#pod |
121
|
|
|
|
|
|
|
#pod This method will place the given piece onto this space. |
122
|
|
|
|
|
|
|
#pod |
123
|
|
|
|
|
|
|
#pod =cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub receive { |
126
|
4
|
|
|
4
|
1
|
10
|
my ($self, $piece) = @_; |
127
|
|
|
|
|
|
|
|
128
|
4
|
50
|
|
|
|
7
|
return unless eval { $piece->isa('Games::Board::Piece') }; |
|
4
|
|
|
|
|
17
|
|
129
|
4
|
50
|
|
|
|
18
|
return if $self->contains($piece); |
130
|
|
|
|
|
|
|
|
131
|
4
|
|
|
|
|
19
|
$piece->{current_space} = $self->id; |
132
|
4
|
|
|
|
|
7
|
push @{$self->{contents}}, $piece->id; |
|
4
|
|
|
|
|
17
|
|
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
#pod =method take |
136
|
|
|
|
|
|
|
#pod |
137
|
|
|
|
|
|
|
#pod $space->take($piece); |
138
|
|
|
|
|
|
|
#pod |
139
|
|
|
|
|
|
|
#pod This method removes the piece from this space. |
140
|
|
|
|
|
|
|
#pod |
141
|
|
|
|
|
|
|
#pod =cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub take { |
144
|
2
|
|
|
2
|
1
|
8
|
my ($self, $piece) = @_; |
145
|
|
|
|
|
|
|
|
146
|
2
|
50
|
|
|
|
5
|
return unless eval { $piece->isa('Games::Board::Piece') }; |
|
2
|
|
|
|
|
30
|
|
147
|
2
|
50
|
|
|
|
22
|
return unless $self->contains($piece); |
148
|
|
|
|
|
|
|
|
149
|
2
|
|
|
|
|
6
|
delete $piece->{current_space}; |
150
|
2
|
|
|
|
|
4
|
$self->{contents} = [ grep { $_ ne $piece->id } @{$self->{contents}} ]; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
8
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |