line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Room.pm,v 1.1 2006/10/31 20:31:21 mike Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Room.pm - a room in a Scott Adams game. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Games::ScottAdams::Room; |
6
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
282
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
20
|
|
|
20
|
0
|
26
|
my $class = shift(); |
11
|
20
|
|
|
|
|
37
|
my($name, $desc, $num) = @_; |
12
|
|
|
|
|
|
|
|
13
|
20
|
|
|
|
|
163
|
return bless { |
14
|
|
|
|
|
|
|
name => $name, |
15
|
|
|
|
|
|
|
desc => $desc, |
16
|
|
|
|
|
|
|
num => $num, # 0-based index into Game's list of rooms |
17
|
|
|
|
|
|
|
exits => {}, # room names indexed by direction |
18
|
|
|
|
|
|
|
}, $class; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub name { |
23
|
63
|
|
|
63
|
0
|
75
|
my $this = shift(); |
24
|
63
|
|
|
|
|
198
|
return $this->{name}; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub desc { |
28
|
20
|
|
|
20
|
0
|
25
|
my $this = shift(); |
29
|
20
|
|
|
|
|
58
|
return $this->{desc}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub num { |
33
|
76
|
|
|
76
|
0
|
82
|
my $this = shift(); |
34
|
76
|
|
|
|
|
222
|
return $this->{num}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub exit { |
39
|
180
|
|
|
180
|
0
|
217
|
my $this = shift(); |
40
|
180
|
|
|
|
|
210
|
my($dir, $dest) = @_; |
41
|
|
|
|
|
|
|
|
42
|
180
|
|
|
|
|
331
|
my $res = $this->{exits}->{$dir}; |
43
|
180
|
100
|
|
|
|
339
|
if (defined $dest) { |
44
|
30
|
|
|
|
|
87
|
$this->{exits}->{$dir} = $dest; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
180
|
|
|
|
|
465
|
return $res; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
### Only for temporary sanity-checking output in Game::compile() |
52
|
|
|
|
|
|
|
#sub describe { |
53
|
|
|
|
|
|
|
# my $this = shift(); |
54
|
|
|
|
|
|
|
# my($game) = @_; |
55
|
|
|
|
|
|
|
# |
56
|
|
|
|
|
|
|
# print $this->{desc}; |
57
|
|
|
|
|
|
|
# foreach my $dir (sort keys %{ $this->{exits} }) { |
58
|
|
|
|
|
|
|
# print "\t$dir -> ", $this->{exits}->{$dir}, "\n"; |
59
|
|
|
|
|
|
|
# } |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# ### Sneaky looking inside the Games::ScottAdams::Item object. |
62
|
|
|
|
|
|
|
# foreach my $item (@{ $game->{items} }) { |
63
|
|
|
|
|
|
|
# if (defined $item->{where} && $item->{where} eq $this->{name}) { |
64
|
|
|
|
|
|
|
# print "[", $item->{name}, "] ", $item->{desc}; |
65
|
|
|
|
|
|
|
# print " (", $item->{alias}, ")" |
66
|
|
|
|
|
|
|
# if defined $item->{alias}; |
67
|
|
|
|
|
|
|
# print "\n"; |
68
|
|
|
|
|
|
|
# } |
69
|
|
|
|
|
|
|
# } |
70
|
|
|
|
|
|
|
#} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |