ScottAdams/Room.pm

filter: Statementstmt 36.8% 7 / 19 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 33.3% 2 / 6 Podpod 0.0% 0 / 5 totaltotal 28.1% 9 / 32 CC 2 SCAR 10.5
CC
2
Cov
33%
exit
6.0
name
2.0
desc
2.0
CRAP 2.9
« ScottAdams/Item.pm ↑ Summary ScottAdams/Game.pm »
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 sub new {
10 1 ▶ my $class = shift();
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 1 my($name, $desc, $num) = @_;
12  
13 1 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 0 ▶ my $this = shift();
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
24 0 return $this->{name};
25 }
26  
27 sub desc {
28 0 ▶ my $this = shift();
Subroutine desc: not called CC=1 SCAR=6.9
Pod undocumented
29 0 return $this->{desc};
30 }
31  
32 sub num {
33 0 ▶ my $this = shift();
Subroutine num: not called CC=1 SCAR=6.9
Pod undocumented
34 0 return $this->{num};
35 }
36  
37  
38 sub exit {
39 0 ▶ my $this = shift();
Subroutine exit: not called CC=2 SCAR=17.9
Pod undocumented
40 0 my($dir, $dest) = @_;
41  
42 0 my $res = $this->{exits}->{$dir};
43 0 ▶ if (defined $dest) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dest) 0 0 0
44 0 $this->{exits}->{$dir} = $dest;
45 }
46  
47 0 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;
« ScottAdams/Item.pm ↑ Summary ScottAdams/Game.pm »