| 1 | # $Id: Item.pm,v 1.1 2006-10-31 20:31:21 mike Exp $ | ||||||||||
| 2 | |||||||||||
| 3 | # Item.pm - an item in a Scott Adams game. | ||||||||||
| 4 | |||||||||||
| 5 | package Games::ScottAdams::Item; | ||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 33 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 10 | 33 | my $class = shift(); | |||||||||
| 11 | 33 | my($name, $desc, $num, $where) = @_; | |||||||||
| 12 | |||||||||||
| 13 | 33 | return bless { | |||||||||
| 14 | name => $name, | ||||||||||
| 15 | desc => $desc, | ||||||||||
| 16 | num => $num, # 0-based index into Game's list of rooms | ||||||||||
| 17 | where => $where, # name of containing room (undef=nowhere) | ||||||||||
| 18 | getdrop => undef, # name for automatic get/drop (if provided) | ||||||||||
| 19 | }, $class; | ||||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | 25 | ▶ | sub name { | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 25 | my $this = shift(); | |||||||||
| 25 | 25 | return $this->{name}; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 33 | ▶ | sub desc { | ||||||||
|
Subroutine
desc: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 29 | 33 | my $this = shift(); | |||||||||
| 30 | 33 | return $this->{desc}; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 67 | ▶ | sub num { | ||||||||
|
Subroutine
num: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 34 | 67 | my $this = shift(); | |||||||||
| 35 | 67 | return $this->{num}; | |||||||||
| 36 | } | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | 55 | ▶ | sub where { | ||||||||
|
Subroutine
where: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 40 | 55 | my $this = shift(); | |||||||||
| 41 | 55 | my($where) = @_; | |||||||||
| 42 | |||||||||||
| 43 | 55 | my $old = $this->{where}; | |||||||||
| 44 | 55 | ▶ | if (defined $where) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 11 | ▶ | undef $where if $where eq ''; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 11 | $this->{where} = $where; | |||||||||
| 47 | } | ||||||||||
| 48 | 55 | return $old; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | |||||||||||
| 52 | # Allow special argument of empty string meaning nowhere | ||||||||||
| 53 | 61 | ▶ | sub getdrop { | ||||||||
|
Subroutine
getdrop: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 54 | 61 | my $this = shift(); | |||||||||
| 55 | 61 | my($name) = @_; | |||||||||
| 56 | |||||||||||
| 57 | 61 | my $old = $this->{getdrop}; | |||||||||
| 58 | 61 | ▶ | if (defined $name) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 14 | $this->{getdrop} = $name; | |||||||||
| 60 | } | ||||||||||
| 61 | 61 | return $old; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | |||||||||||
| 65 | 1 | 1; | |||||||||