line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::Wumpus::Room; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
36490
|
use 5.010; |
|
5
|
|
|
|
|
19
|
|
|
5
|
|
|
|
|
217
|
|
4
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
27
|
use strict; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
184
|
|
6
|
5
|
|
|
5
|
|
26
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
189
|
|
7
|
5
|
|
|
5
|
|
38
|
no warnings 'syntax'; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
498
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '2009112401'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# Room in the cave of a Wumpus game. |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
5
|
|
4945
|
use Hash::Util::FieldHash qw [fieldhash]; |
|
5
|
|
|
|
|
5065
|
|
|
5
|
|
|
|
|
310
|
|
16
|
5
|
|
|
5
|
|
577
|
use Games::Wumpus::Constants; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
23566
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
fieldhash my %name; # 'Name' of the room; typically a positive integer. |
19
|
|
|
|
|
|
|
fieldhash my %hazard; # 'Hazards' the room may contain. |
20
|
|
|
|
|
|
|
fieldhash my %exit; # 'Tunnels' to other rooms. List of objects. |
21
|
|
|
|
|
|
|
|
22
|
41
|
|
|
41
|
1
|
552
|
sub new {bless \do {my $var} => shift} |
|
41
|
|
|
|
|
134
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub init { |
25
|
41
|
|
|
41
|
1
|
47
|
my $self = shift; |
26
|
|
|
|
|
|
|
|
27
|
41
|
|
|
|
|
248
|
$hazard {$self} = 0; |
28
|
41
|
|
|
|
|
127
|
$exit {$self} = []; |
29
|
|
|
|
|
|
|
|
30
|
41
|
|
|
|
|
136
|
$self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# |
34
|
|
|
|
|
|
|
# Accessors |
35
|
|
|
|
|
|
|
# |
36
|
41
|
|
|
41
|
1
|
677
|
sub set_name {$name {$_ [0]} = $_ [1]; $_ [0]} |
|
41
|
|
|
|
|
171
|
|
37
|
377
|
|
|
377
|
1
|
1974
|
sub name {$name {$_ [0]}} |
38
|
|
|
|
|
|
|
|
39
|
16
|
|
|
16
|
1
|
13919
|
sub set_hazard {$hazard {$_ [0]} |= $_ [1]; $_ [0]} |
|
16
|
|
|
|
|
51
|
|
40
|
26
|
|
|
26
|
1
|
7867
|
sub hazards {$hazard {$_ [0]}} |
41
|
1
|
|
|
1
|
1
|
5
|
sub clear_hazard {$hazard {$_ [0]} &= ~$_ [1]; $_ [0]} |
|
1
|
|
|
|
|
5
|
|
42
|
21
|
|
|
21
|
1
|
71
|
sub clear_hazards {$hazard {$_ [0]} = 0; $_ [0]} |
|
21
|
|
|
|
|
36
|
|
43
|
30
|
|
|
30
|
1
|
134
|
sub has_hazard {$hazard {$_ [0]} & $_ [1]} |
44
|
|
|
|
|
|
|
|
45
|
122
|
|
|
122
|
1
|
113
|
sub add_exit {push @{$exit {$_ [0]}} => $_ [1]; $_ [0]} |
|
122
|
|
|
|
|
242
|
|
|
122
|
|
|
|
|
312
|
|
46
|
102
|
|
|
102
|
1
|
8041
|
sub exits { @{$exit {$_ [0]}}} |
|
102
|
|
|
|
|
372
|
|
47
|
|
|
|
|
|
|
sub exit_by_name { |
48
|
63
|
|
|
63
|
1
|
25079
|
my $self = shift; |
49
|
63
|
|
|
|
|
109
|
my $name = shift; |
50
|
63
|
|
|
|
|
121
|
my ($e) = grep {$_ -> name eq $name} $self -> exits; |
|
186
|
|
|
|
|
317
|
|
51
|
63
|
|
|
|
|
158
|
return $e; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# |
55
|
|
|
|
|
|
|
# Hazards nearby? |
56
|
|
|
|
|
|
|
# |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub near_hazard { |
59
|
12
|
|
|
12
|
1
|
16
|
my $self = shift; |
60
|
12
|
|
|
|
|
10
|
my $hazard = shift; |
61
|
12
|
|
|
|
|
29
|
foreach my $exit ($self -> exits) { |
62
|
28
|
100
|
|
|
|
2613
|
return 1 if $exit -> has_hazard ($hazard); |
63
|
|
|
|
|
|
|
} |
64
|
6
|
|
|
|
|
36
|
return 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |