line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Game.pm,v 1.1 2006/10/31 20:31:21 mike Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Game.pm - class to represent an entire Scott Adams game. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Games::ScottAdams::Game; |
6
|
1
|
|
|
1
|
|
15
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
58
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# This whole-game class is dependent on subsidiary classes to |
10
|
|
|
|
|
|
|
# represent the specific game concepts of Room, Item and Action. |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
1680
|
use Games::ScottAdams::Parse; # additional methods for this class |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
32
|
|
13
|
1
|
|
|
1
|
|
736
|
use Games::ScottAdams::Compile; # additional methods for this class |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
14
|
1
|
|
|
1
|
|
762
|
use Games::ScottAdams::Room; |
|
1
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
33
|
|
15
|
1
|
|
|
1
|
|
697
|
use Games::ScottAdams::Item; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
16
|
1
|
|
|
1
|
|
566
|
use Games::ScottAdams::Action; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
207
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
1
|
|
|
1
|
0
|
55
|
my $class = shift(); |
21
|
1
|
|
|
|
|
24
|
my $this = bless { |
22
|
|
|
|
|
|
|
@_, |
23
|
|
|
|
|
|
|
rooms => [], # array of Games::ScottAdams::Room |
24
|
|
|
|
|
|
|
roomname => {}, # ... and indexed by name |
25
|
|
|
|
|
|
|
items => [], # array of Games::ScottAdams::Item |
26
|
|
|
|
|
|
|
itemname => {}, # ... and indexed by name |
27
|
|
|
|
|
|
|
actions => [], # array of Games::ScottAdams::Action |
28
|
|
|
|
|
|
|
messages => [], # array of message strings |
29
|
|
|
|
|
|
|
msgmap => {}, # ... and indexed by message |
30
|
|
|
|
|
|
|
vvocab => {}, # map of verbs to equivalence classes |
31
|
|
|
|
|
|
|
nvocab => {}, # map of nouns to equivalence classes |
32
|
|
|
|
|
|
|
# Vocabulary information is accumulated in {vvocab} |
33
|
|
|
|
|
|
|
# and {nvocab} during parsing. At the end of the |
34
|
|
|
|
|
|
|
# parsing phase, they are rationalised into arrays |
35
|
|
|
|
|
|
|
# {nouns} and {verbs}, together with inverted indexes |
36
|
|
|
|
|
|
|
# in the hashes {nmap} and {vmap}. |
37
|
|
|
|
|
|
|
start => undef, # name of room where player starts |
38
|
|
|
|
|
|
|
treasury => undef, # name of room where treasure is stored |
39
|
|
|
|
|
|
|
maxload => undef, # how many items player can carry at once |
40
|
|
|
|
|
|
|
lighttime => undef, # how many turns the light source works for |
41
|
|
|
|
|
|
|
ident => undef, # magic number identifying this adventure |
42
|
|
|
|
|
|
|
version => undef, # version number of this adventure |
43
|
|
|
|
|
|
|
wordlen => undef, # number of significant characters in words |
44
|
|
|
|
|
|
|
lightsource => undef, # name of item which functions as light source |
45
|
|
|
|
|
|
|
ntreasures => 0, # number of items starting with "*" |
46
|
|
|
|
|
|
|
_room => undef, # reference to current room during parsing |
47
|
|
|
|
|
|
|
_item => undef, # reference to current item during parsing |
48
|
|
|
|
|
|
|
_action => undef, # reference to current action during parsing |
49
|
|
|
|
|
|
|
_roomname1 => undef, # name of first room to be defined |
50
|
|
|
|
|
|
|
}, $class; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Room zero is always special - it's where items not in play |
53
|
|
|
|
|
|
|
# reside. We stick a vacuous one at the front of the array. |
54
|
1
|
|
|
|
|
11
|
my $room = new Games::ScottAdams::Room('NOWHERE', '[nowhere]', 0); |
55
|
1
|
|
|
|
|
2
|
push @{ $this->{rooms} }, $room; |
|
1
|
|
|
|
|
7
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Message 0 is useless, since action 0 is NOP; so occupy its space. |
58
|
1
|
|
|
|
|
6
|
$this->resolve_message('[dummy]'); |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
|
|
3
|
return $this; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |