| 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 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 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 | ▶ | use Games::ScottAdams::Parse; # additional methods for this class |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 13 | 1 | ▶ | use Games::ScottAdams::Compile; # additional methods for this class |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 14 | 1 | ▶ | use Games::ScottAdams::Room; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 15 | 1 | ▶ | use Games::ScottAdams::Item; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 16 | 1 | ▶ | use Games::ScottAdams::Action; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 17 | |||
| 18 | |||
| 19 | 1 | ▶ | sub new { |
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 20 | 1 | my $class = shift(); | |
| 21 | 1 | 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 | my $room = new Games::ScottAdams::Room('NOWHERE', '[nowhere]', 0); | |
| 55 | 1 | push @{ $this->{rooms} }, $room; | |
| 56 | |||
| 57 | # Message 0 is useless, since action 0 is NOP; so occupy its space. | ||
| 58 | 1 | $this->resolve_message('[dummy]'); | |
| 59 | |||
| 60 | 1 | return $this; | |
| 61 | } | ||
| 62 | |||
| 63 | |||
| 64 | 1 | 1; | |