line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Game::TextPacMonster::Player; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
458
|
use strict; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
86
|
|
4
|
4
|
|
|
4
|
|
17
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
74
|
|
5
|
4
|
|
|
4
|
|
30
|
use utf8; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
20
|
|
6
|
4
|
|
|
4
|
|
466
|
use Game::TextPacMonster::Point; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
99
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
20
|
use base 'Game::TextPacMonster::Creature'; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
2193
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
22
|
|
|
22
|
0
|
48
|
my $class = shift @_; |
12
|
22
|
|
|
|
|
90
|
my $self = $class->SUPER::new(@_); |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub _get_function { |
16
|
30
|
|
|
30
|
|
93
|
my ( $self, $command ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
30
|
100
|
|
|
|
75
|
return 0 if ( !$command ); |
19
|
|
|
|
|
|
|
|
20
|
27
|
|
|
|
|
149
|
my %command_function_map = ( |
21
|
|
|
|
|
|
|
'.' => 'stay', |
22
|
|
|
|
|
|
|
'j' => 'move_down', |
23
|
|
|
|
|
|
|
'k' => 'move_up', |
24
|
|
|
|
|
|
|
'h' => 'move_left', |
25
|
|
|
|
|
|
|
'l' => 'move_right', |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
27
|
100
|
|
|
|
71
|
return 0 if ( !$command_function_map{$command} ); |
29
|
23
|
|
|
|
|
86
|
return $command_function_map{$command}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub can_move { |
33
|
15
|
|
|
15
|
0
|
42
|
my ( $self, $command ) = @_; |
34
|
|
|
|
|
|
|
|
35
|
15
|
|
|
|
|
35
|
my $f = $self->_get_function($command); |
36
|
15
|
100
|
|
|
|
49
|
return 0 if ( !$f ); |
37
|
|
|
|
|
|
|
|
38
|
11
|
|
|
|
|
38
|
my $x = $self->{_point}->x_coord; |
39
|
11
|
|
|
|
|
33
|
my $y = $self->{_point}->y_coord; |
40
|
|
|
|
|
|
|
|
41
|
11
|
100
|
|
|
|
51
|
if ( $f eq 'move_down' ) { |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
42
|
3
|
|
|
|
|
7
|
++$y; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
elsif ( $f eq 'move_up' ) { |
45
|
2
|
|
|
|
|
3
|
--$y; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
elsif ( $f eq 'move_left' ) { |
48
|
3
|
|
|
|
|
12
|
--$x; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ( $f eq 'move_right' ) { |
51
|
3
|
|
|
|
|
13
|
++$x; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
elsif ( $f eq 'stay' ) { |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# do nothing |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
else { |
58
|
0
|
|
|
|
|
0
|
return 0; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
11
|
|
|
|
|
35
|
my $next_point = Game::TextPacMonster::Point->new( $x, $y ); |
62
|
|
|
|
|
|
|
|
63
|
11
|
|
|
|
|
61
|
return $self->{_map}->can_move($next_point); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub move { |
67
|
8
|
|
|
8
|
0
|
21
|
my ( $self, $command ) = @_; |
68
|
|
|
|
|
|
|
|
69
|
8
|
|
|
|
|
20
|
my $f = $self->_get_function($command); |
70
|
|
|
|
|
|
|
|
71
|
8
|
100
|
66
|
|
|
91
|
if ( $f && $self->$f ) { |
72
|
7
|
|
|
|
|
18
|
$self->_eat(); |
73
|
7
|
|
|
|
|
27
|
return 1; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
8
|
return 0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _eat { |
80
|
7
|
|
|
7
|
|
11
|
my $self = shift; |
81
|
7
|
|
|
|
|
21
|
$self->{_map}->del_feed( $self->point ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|