| 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 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 20 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 10 | 20 | my $class = shift(); | |||||||||
| 11 | 20 | my($name, $desc, $num) = @_; | |||||||||
| 12 | |||||||||||
| 13 | 20 | 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 | 63 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 23 | 63 | my $this = shift(); | |||||||||
| 24 | 63 | return $this->{name}; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 20 | ▶ | sub desc { | ||||||||
|
Subroutine
desc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 28 | 20 | my $this = shift(); | |||||||||
| 29 | 20 | return $this->{desc}; | |||||||||
| 30 | } | ||||||||||
| 31 | |||||||||||
| 32 | 76 | ▶ | sub num { | ||||||||
|
Subroutine
num: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 33 | 76 | my $this = shift(); | |||||||||
| 34 | 76 | return $this->{num}; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | 180 | ▶ | sub exit { | ||||||||
|
Subroutine
exit: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 39 | 180 | my $this = shift(); | |||||||||
| 40 | 180 | my($dir, $dest) = @_; | |||||||||
| 41 | |||||||||||
| 42 | 180 | my $res = $this->{exits}->{$dir}; | |||||||||
| 43 | 180 | ▶ | if (defined $dest) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 30 | $this->{exits}->{$dir} = $dest; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 180 | 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 | 1; | |||||||||