line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Game::TextPacMonster; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
596
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
5
|
2
|
|
|
2
|
|
708
|
use utf8; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
6
|
2
|
|
|
2
|
|
12
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
197
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
1256
|
use Game::TextPacMonster::Map; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1830
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub level1 { |
13
|
1
|
|
|
1
|
0
|
685
|
my $map = <<'EOF'; |
14
|
|
|
|
|
|
|
########### |
15
|
|
|
|
|
|
|
#.V..#..H.# |
16
|
|
|
|
|
|
|
#.##...##.# |
17
|
|
|
|
|
|
|
#L#..#..R.# |
18
|
|
|
|
|
|
|
#.#.###.#.# |
19
|
|
|
|
|
|
|
#....@....# |
20
|
|
|
|
|
|
|
########### |
21
|
|
|
|
|
|
|
EOF |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
7
|
return Game::TextPacMonster->new( |
24
|
|
|
|
|
|
|
{ |
25
|
|
|
|
|
|
|
timelimit => 50, |
26
|
|
|
|
|
|
|
map_string => $map |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub level2 { |
33
|
2
|
|
|
2
|
0
|
14
|
my $map = <<'EOF'; |
34
|
|
|
|
|
|
|
#################### |
35
|
|
|
|
|
|
|
###.....L..........# |
36
|
|
|
|
|
|
|
###.##.##.##L##.##.# |
37
|
|
|
|
|
|
|
###.##.##.##.##.##.# |
38
|
|
|
|
|
|
|
#.L................# |
39
|
|
|
|
|
|
|
#.##.##.##.##.##.### |
40
|
|
|
|
|
|
|
#.##.##L##.##.##.### |
41
|
|
|
|
|
|
|
#.................L# |
42
|
|
|
|
|
|
|
#.#.#.#J####J#.#.#.# |
43
|
|
|
|
|
|
|
#L.................# |
44
|
|
|
|
|
|
|
###.##.##.##.##.##.# |
45
|
|
|
|
|
|
|
###.##.##R##.##.##.# |
46
|
|
|
|
|
|
|
#................R.# |
47
|
|
|
|
|
|
|
#.##.##.##.##R##.### |
48
|
|
|
|
|
|
|
#.##.##.##.##.##.### |
49
|
|
|
|
|
|
|
#@....R..........### |
50
|
|
|
|
|
|
|
#################### |
51
|
|
|
|
|
|
|
EOF |
52
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
12
|
return Game::TextPacMonster->new( |
54
|
|
|
|
|
|
|
{ |
55
|
|
|
|
|
|
|
timelimit => 300, |
56
|
|
|
|
|
|
|
map_string => $map |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub level3 { |
63
|
0
|
|
|
0
|
0
|
0
|
my $map = <<"EOF"; |
64
|
|
|
|
|
|
|
########################################################## |
65
|
|
|
|
|
|
|
#........................................................# |
66
|
|
|
|
|
|
|
#.###.#########.###############.########.###.#####.#####.# |
67
|
|
|
|
|
|
|
#.###.#########.###############.########.###.#####.#####.# |
68
|
|
|
|
|
|
|
#.....#########....J.............J.......###.............# |
69
|
|
|
|
|
|
|
#####.###.......#######.#######.########.###.#######.##### |
70
|
|
|
|
|
|
|
#####.###.#####J#######.#######.########.###.## ##.##### |
71
|
|
|
|
|
|
|
#####.###L#####.## ##L## ##.## ##.###.## ##.##### |
72
|
|
|
|
|
|
|
#####.###..H###.## ##.## ##.########.###.#######J##### |
73
|
|
|
|
|
|
|
#####.#########.## ##L## ##.########.###.###V....##### |
74
|
|
|
|
|
|
|
#####.#########.#######.#######..........###.#######.##### |
75
|
|
|
|
|
|
|
#####.#########.#######.#######.########.###.#######.##### |
76
|
|
|
|
|
|
|
#.....................L.........########..........R......# |
77
|
|
|
|
|
|
|
#L####.##########.##.##########....##....#########.#####.# |
78
|
|
|
|
|
|
|
#.####.##########.##.##########.##.##.##.#########.#####.# |
79
|
|
|
|
|
|
|
#.................##............##..@.##...............R.# |
80
|
|
|
|
|
|
|
########################################################## |
81
|
|
|
|
|
|
|
EOF |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
return Game::TextPacMonster->new( |
84
|
|
|
|
|
|
|
{ |
85
|
|
|
|
|
|
|
timelimit => 700, |
86
|
|
|
|
|
|
|
map_string => $map |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub new { |
92
|
13
|
|
|
13
|
0
|
4899
|
my ( $class, $map_info_ref ) = @_; |
93
|
|
|
|
|
|
|
|
94
|
13
|
|
|
|
|
38
|
my $wrong = Game::TextPacMonster->_do_input_validation($map_info_ref); |
95
|
13
|
100
|
|
|
|
37
|
if ($wrong) { |
96
|
10
|
|
|
|
|
1123
|
croak $wrong; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
3
|
|
|
|
|
7
|
chomp( $map_info_ref->{map_string} ); |
100
|
|
|
|
|
|
|
|
101
|
3
|
|
|
|
|
20
|
my $self = { _map => Game::TextPacMonster::Map->new($map_info_ref) }; |
102
|
|
|
|
|
|
|
|
103
|
3
|
|
|
|
|
8
|
bless $self, $class; |
104
|
3
|
|
|
|
|
10
|
return $self; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub run { |
109
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
110
|
0
|
|
|
|
|
0
|
my $map = $self->{_map}; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
my $order = q{}; |
113
|
0
|
|
|
|
|
0
|
my $win_message = 'You win'; |
114
|
0
|
|
|
|
|
0
|
my $message = 'You lose!!!'; # lose message default |
115
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
while (1) { |
117
|
0
|
|
|
|
|
0
|
system('clear'); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
0
|
print $map->get_string ."\n"; |
120
|
0
|
|
|
|
|
0
|
print 'feed(s) left: ' . $map->count_feeds . "\n"; |
121
|
0
|
|
|
|
|
0
|
print 'time left: ' . $map->get_left_time . "\n"; |
122
|
0
|
|
|
|
|
0
|
print 'log: ' . $map->get_log . "\n"; |
123
|
|
|
|
|
|
|
|
124
|
0
|
0
|
0
|
|
|
0
|
if ($map->is_lose || $map->is_win) { |
125
|
0
|
0
|
|
|
|
0
|
$message = 'You win!!!' if $map->is_win; |
126
|
0
|
|
|
|
|
0
|
last; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
0
|
print 'Your turn [k/j/h/l/.]: '; |
130
|
0
|
|
|
|
|
0
|
$order = ; |
131
|
0
|
|
|
|
|
0
|
chomp $order; |
132
|
0
|
|
|
|
|
0
|
$map->command_player($order); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
0
|
print "$message\n"; |
136
|
0
|
|
|
|
|
0
|
exit; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub _do_input_validation { |
143
|
13
|
|
|
13
|
|
16
|
my ( $class, $input ) = @_; |
144
|
|
|
|
|
|
|
|
145
|
13
|
100
|
|
|
|
36
|
if ( !defined( $input->{timelimit} ) ) { |
146
|
1
|
|
|
|
|
3
|
return q/An input param 'timelimit' has not been set./; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
12
|
100
|
|
|
|
28
|
if ( !defined( $input->{map_string} ) ) { |
150
|
1
|
|
|
|
|
3
|
return q/An input param 'map_string' has not been set./; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
11
|
100
|
|
|
|
25
|
if ( $input->{timelimit} <= 0 ) { |
154
|
2
|
|
|
|
|
5
|
return q/An input param 'timelimit' should be lager than 0./; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
9
|
100
|
|
|
|
82
|
if ( $input->{map_string} !~ qr/\./m ) { |
158
|
1
|
|
|
|
|
3
|
return q/An input param 'map_string' should include '.' ./; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
8
|
100
|
|
|
|
71
|
if ( $input->{map_string} =~ qr/[^#VHLRJ@.\s]/m ) { |
162
|
|
|
|
|
|
|
return |
163
|
1
|
|
|
|
|
2
|
q/An input param 'map_string' should be char set '#VHLRJ@.' and 'SPACE' ./; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
7
|
|
|
|
|
44
|
my $match_num = scalar( () = $input->{map_string} =~ /@/g ); |
167
|
7
|
100
|
|
|
|
17
|
if ( $match_num != 1 ) { |
168
|
|
|
|
|
|
|
return |
169
|
2
|
|
|
|
|
5
|
q/An input param 'map_string' should inculde just only one '@' ./; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# to make array like $map[height][width] |
173
|
5
|
|
|
|
|
24
|
chomp $input->{map_string}; |
174
|
910
|
|
|
|
|
1199
|
my @map = map { |
175
|
5
|
|
|
|
|
41
|
my @x_map = map { $_ } split( //, $_ ); |
|
55
|
|
|
|
|
169
|
|
176
|
55
|
|
|
|
|
165
|
\@x_map; |
177
|
|
|
|
|
|
|
} split( /\n/, $input->{map_string} ); |
178
|
|
|
|
|
|
|
|
179
|
5
|
|
|
|
|
12
|
my $width_valid = 1; |
180
|
5
|
|
|
|
|
6
|
my $w = scalar( @{ $map[0] } ); # width |
|
5
|
|
|
|
|
8
|
|
181
|
5
|
|
|
|
|
6
|
my $h = scalar(@map); # height |
182
|
5
|
|
|
|
|
11
|
for (@map) { |
183
|
55
|
100
|
|
|
|
106
|
$width_valid = 0 if ( $w != scalar(@$_) ); |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
5
|
|
|
|
|
8
|
my $surface_valid = 1; |
187
|
|
|
|
|
|
|
|
188
|
5
|
|
|
|
|
13
|
for ( 0 .. ( $w - 1 ) ) { |
189
|
72
|
100
|
|
|
|
174
|
$surface_valid = 0 if ( $map[0][$_] . $map[ $h - 1 ][$_] ne '##' ); |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
5
|
|
|
|
|
12
|
for ( 0 .. ( $h - 1 ) ) { |
193
|
55
|
100
|
|
|
|
161
|
$surface_valid = 0 if ( $map[$_][0] . $map[$_][ $w - 1 ] ne '##' ); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
5
|
100
|
|
|
|
15
|
if ( !$width_valid ) { |
197
|
1
|
|
|
|
|
7
|
return q/An input param 'map_string' should shape square' ./; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
4
|
100
|
|
|
|
10
|
if ( !$surface_valid ) { |
201
|
1
|
|
|
|
|
11
|
return q/An input param 'map_string' s 4 sides should be all '#' ./; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
3
|
|
|
|
|
66
|
return 0; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
1; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
__END__ |