From ecf3cabe62314a44460b0bfb228e62e668336425 Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Tue, 24 Jul 2012 22:57:20 +0200 Subject: [PATCH] [bin/crypt] can't take the helmet in darkness --- bin/crypt | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/bin/crypt b/bin/crypt index d59f6bb..6887cc5 100755 --- a/bin/crypt +++ b/bin/crypt @@ -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 @@ -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) + if $pitch_black; + die X::Adventure::NoSuchThingHere.new(:$thing) unless self!is_thing_in($thing, $!player_location); @@ -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; }