Skip to content

Commit

Permalink
[bin/crypt] can't take the helmet in darkness
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Jul 24, 2012
1 parent e4f2c0c commit ecf3cab
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions bin/crypt
Expand Up @@ -460,6 +460,14 @@ class X::Adventure::PlayerDoesNotHave is X::Adventure {
}
}

class X::Adventure::PitchBlack is X::Adventure {
has $.action;

method message {
"You cannot $.action anything, because it is pitch black"
}
}

class Adventure::Engine {
my @possible_directions = <
north south east west
Expand Down Expand Up @@ -791,6 +799,12 @@ class Adventure::Engine {
die X::Adventure::PlayerAlreadyCarries.new(:$thing)
if (%!thing_rooms{$thing} // '') eq 'player inventory';

my $pitch_black = %!dark_rooms{$!player_location}
&& !self!shining_thing_here($!player_location);

die X::Adventure::PitchBlack.new(:action<take>)
if $pitch_black;

die X::Adventure::NoSuchThingHere.new(:$thing)
unless self!is_thing_in($thing, $!player_location);

Expand Down Expand Up @@ -2354,6 +2368,21 @@ multi MAIN('test') {
'taking the helmet (+)';
}

{
my $game = game_from_hall();

throws_exception
{ $game.take('helmet') },
X::Adventure::PitchBlack,
'taking the helmet (-) pitch black',
{
is .action, 'take', '.action attribute';
is .message,
"You cannot take anything, because it is pitch black",
'.message attribute';
};
}

done;
}

Expand Down

0 comments on commit ecf3cab

Please sign in to comment.