Skip to content

Commit

Permalink
[bin/crypt] can't open a hidden thing
Browse files Browse the repository at this point in the history
Or a thing which is in another room.
  • Loading branch information
Carl Masak committed Jul 14, 2012
1 parent 2bfc22d commit 20e37ab
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions bin/crypt
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,12 @@ class Adventure::Engine {
die X::Adventure::PlayerIsNowhere.new()
unless defined $!player_location;

die X::Adventure::NoSuchThingHere.new(:$thing)
unless (%!thing_rooms{$thing} // '') eq $!player_location;

die X::Adventure::NoSuchThingHere.new(:$thing)
if %!hidden_things{$thing};

die X::Adventure::ThingNotOpenable.new(:$thing)
unless %!openable_things{$thing};

Expand Down Expand Up @@ -1321,6 +1327,31 @@ multi MAIN('test') {
'examining a hidden thing (-) cannot because it is hidden';
}

{
my $engine = Adventure::Engine.new();

$engine.place_thing('flask', 'chamber');
$engine.make_thing_openable('flask');
$engine.hide_thing('flask');
$engine.place_player('chamber');
throws_exception
{ $engine.open('flask') },
X::Adventure::NoSuchThingHere,
'opening a hidden thing (-) cannot because it is hidden';
}

{
my $engine = Adventure::Engine.new();

$engine.place_thing('flask', 'chamber');
$engine.make_thing_openable('flask');
$engine.place_player('bedroom');
throws_exception
{ $engine.open('flask') },
X::Adventure::NoSuchThingHere,
'opening a thing (-) cannot because it is in another room';
}

done;
}

Expand Down

0 comments on commit 20e37ab

Please sign in to comment.