line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Game::TextPacMonster::Creature; |
2
|
10
|
|
|
10
|
|
667
|
use strict; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
253
|
|
3
|
10
|
|
|
10
|
|
50
|
use warnings; |
|
10
|
|
|
|
|
16
|
|
|
10
|
|
|
|
|
210
|
|
4
|
10
|
|
|
10
|
|
64
|
use utf8; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
47
|
|
5
|
|
|
|
|
|
|
|
6
|
10
|
|
|
10
|
|
539
|
use Game::TextPacMonster::Point; |
|
10
|
|
|
|
|
23
|
|
|
10
|
|
|
|
|
12417
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new { |
9
|
163
|
|
|
163
|
0
|
1623
|
my ( $class, $id, $point, $map ) = @_; |
10
|
163
|
|
|
|
|
587
|
my $self = { |
11
|
|
|
|
|
|
|
_id => $id, |
12
|
|
|
|
|
|
|
_point => $point, |
13
|
|
|
|
|
|
|
_pre_point => undef, |
14
|
|
|
|
|
|
|
_map => $map, |
15
|
|
|
|
|
|
|
}; |
16
|
163
|
|
|
|
|
671
|
bless $self, $class; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub id { |
20
|
1
|
|
|
1
|
0
|
6
|
my $self = shift; |
21
|
1
|
|
|
|
|
7
|
return $self->{_id}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub point { |
25
|
705
|
|
|
705
|
0
|
963
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
705
|
100
|
|
|
|
1327
|
if (@_) { |
28
|
128
|
|
|
|
|
216
|
$self->{_pre_point} = $self->{_point}; |
29
|
128
|
|
|
|
|
178
|
$self->{_point} = shift; |
30
|
128
|
|
|
|
|
184
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
else { |
33
|
577
|
|
|
|
|
1863
|
return $self->{_point}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub move_free { |
38
|
2
|
|
|
2
|
0
|
34
|
die "it should be overrided on sub class"; |
39
|
0
|
|
|
|
|
0
|
return 0; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub move { |
43
|
14
|
|
|
14
|
0
|
26
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
14
|
100
|
|
|
|
51
|
return 1 if $self->move_first; |
46
|
|
|
|
|
|
|
|
47
|
8
|
|
|
|
|
31
|
my $counted_ways = $self->{_map}->count_movable_points( $self->point ); |
48
|
|
|
|
|
|
|
|
49
|
8
|
100
|
|
|
|
25
|
return $self->move_back if $counted_ways == 1; |
50
|
7
|
100
|
|
|
|
34
|
return $self->move_forward if $counted_ways == 2; |
51
|
3
|
|
|
|
|
16
|
return $self->move_free; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub move_forward { |
55
|
8
|
|
|
8
|
0
|
20
|
my $self = shift; |
56
|
8
|
|
|
|
|
29
|
my $pre = $self->pre_point; |
57
|
8
|
|
|
|
|
26
|
my $now = $self->point; |
58
|
|
|
|
|
|
|
|
59
|
8
|
|
|
|
|
32
|
my $ways = [ |
60
|
|
|
|
|
|
|
Game::TextPacMonster::Point->new( |
61
|
|
|
|
|
|
|
$now->x_coord + 1, |
62
|
|
|
|
|
|
|
$now->y_coord |
63
|
|
|
|
|
|
|
), # go right |
64
|
|
|
|
|
|
|
Game::TextPacMonster::Point->new( |
65
|
|
|
|
|
|
|
$now->x_coord - 1, |
66
|
|
|
|
|
|
|
$now->y_coord |
67
|
|
|
|
|
|
|
), # go left |
68
|
|
|
|
|
|
|
Game::TextPacMonster::Point->new( |
69
|
|
|
|
|
|
|
$now->x_coord, $now->y_coord + 1 |
70
|
|
|
|
|
|
|
), # go down |
71
|
|
|
|
|
|
|
Game::TextPacMonster::Point->new( |
72
|
|
|
|
|
|
|
$now->x_coord, $now->y_coord - 1 |
73
|
|
|
|
|
|
|
), # go up |
74
|
|
|
|
|
|
|
]; |
75
|
|
|
|
|
|
|
|
76
|
8
|
|
|
|
|
25
|
for my $way (@$ways) { |
77
|
19
|
100
|
100
|
|
|
60
|
return 1 if ( !$way->equals($pre) && $self->_move_point($way) ); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
return 0; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub pre_point { |
84
|
85
|
|
|
85
|
0
|
109
|
my $self = shift; |
85
|
85
|
|
|
|
|
224
|
return $self->{_pre_point}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub stay { |
89
|
2
|
|
|
2
|
0
|
11
|
my $self = shift; |
90
|
2
|
|
|
|
|
10
|
my $p = $self->point; |
91
|
|
|
|
|
|
|
|
92
|
2
|
|
|
|
|
12
|
$self->point( Game::TextPacMonster::Point->new( $p->x_coord, $p->y_coord ) ); |
93
|
2
|
|
|
|
|
10
|
return 1; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub get_relative_point { |
97
|
21
|
|
|
21
|
0
|
31
|
my $self = shift; |
98
|
|
|
|
|
|
|
|
99
|
21
|
|
|
|
|
488949
|
my $player = $self->get_player_point; |
100
|
21
|
|
|
|
|
114
|
my $me = $self->point; |
101
|
|
|
|
|
|
|
|
102
|
21
|
|
|
|
|
74
|
my $x = $player->x_coord - $me->x_coord; |
103
|
21
|
|
|
|
|
70
|
my $y = $player->y_coord - $me->y_coord; |
104
|
|
|
|
|
|
|
|
105
|
21
|
|
|
|
|
76
|
return Game::TextPacMonster::Point->new( $x, $y ); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub get_player_point { |
109
|
22
|
|
|
22
|
0
|
56
|
my $self = shift; |
110
|
22
|
|
|
|
|
199
|
return $self->{_map}->get_player_point; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub move_first { |
114
|
20
|
|
|
20
|
0
|
40
|
my $self = shift; |
115
|
|
|
|
|
|
|
|
116
|
20
|
100
|
|
|
|
198
|
if ( $self->{_map}->get_time == 0 ) { |
117
|
12
|
|
|
|
|
31
|
my @methods = qw( move_down move_left move_up move_right); |
118
|
|
|
|
|
|
|
|
119
|
12
|
|
|
|
|
24
|
for (@methods) { |
120
|
28
|
100
|
|
|
|
101
|
return 1 if ( $self->$_ ); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
10
|
|
|
|
|
31
|
return 0; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub move_back { |
128
|
2
|
|
|
2
|
0
|
10
|
my $self = shift; |
129
|
2
|
|
|
|
|
8
|
my $p = $self->pre_point; |
130
|
2
|
|
|
|
|
8
|
my $next_p = Game::TextPacMonster::Point->new( $p->x_coord, $p->y_coord ); |
131
|
2
|
|
|
|
|
8
|
return $self->_move_point($next_p); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub move_up { |
135
|
47
|
|
|
47
|
0
|
571
|
my $self = shift; |
136
|
47
|
|
|
|
|
97
|
my $p = $self->point; |
137
|
47
|
|
|
|
|
143
|
my $next_p = |
138
|
|
|
|
|
|
|
Game::TextPacMonster::Point->new( $p->x_coord, $p->y_coord - 1 ); |
139
|
47
|
|
|
|
|
119
|
return $self->_move_point($next_p); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub move_down { |
143
|
59
|
|
|
59
|
0
|
549
|
my $self = shift; |
144
|
59
|
|
|
|
|
138
|
my $p = $self->point; |
145
|
59
|
|
|
|
|
183
|
my $next_p = |
146
|
|
|
|
|
|
|
Game::TextPacMonster::Point->new( $p->x_coord, $p->y_coord + 1 ); |
147
|
59
|
|
|
|
|
202
|
return $self->_move_point($next_p); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub move_right { |
151
|
51
|
|
|
51
|
0
|
115
|
my $self = shift; |
152
|
51
|
|
|
|
|
118
|
my $p = $self->point; |
153
|
51
|
|
|
|
|
228
|
my $next_p = |
154
|
|
|
|
|
|
|
Game::TextPacMonster::Point->new( $p->x_coord + 1, $p->y_coord ); |
155
|
51
|
|
|
|
|
148
|
return $self->_move_point($next_p); |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub move_left { |
159
|
56
|
|
|
56
|
0
|
642
|
my $self = shift; |
160
|
56
|
|
|
|
|
111
|
my $p = $self->point; |
161
|
56
|
|
|
|
|
225
|
my $next_p = |
162
|
|
|
|
|
|
|
Game::TextPacMonster::Point->new( $p->x_coord - 1, $p->y_coord ); |
163
|
56
|
|
|
|
|
136
|
return $self->_move_point($next_p); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub _move_point { |
167
|
232
|
|
|
232
|
|
310
|
my ( $self, $point ) = @_; |
168
|
|
|
|
|
|
|
|
169
|
232
|
100
|
|
|
|
1250
|
if ( $self->{_map}->can_move($point) ) { |
170
|
124
|
|
|
|
|
261
|
$self->point($point); |
171
|
124
|
|
|
|
|
800
|
return 1; |
172
|
|
|
|
|
|
|
} |
173
|
108
|
|
|
|
|
440
|
return 0; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |