Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bin/crypt] can't take the helmet in darkness

  • Loading branch information...
commit ecf3cabe62314a44460b0bfb228e62e668336425 1 parent e4f2c0c
Carl Mäsak authored
Showing with 29 additions and 0 deletions.
  1. +29 −0 bin/crypt
29 bin/crypt
View
@@ -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<take>)
+ 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;
}
Please sign in to comment.
Something went wrong with that request. Please try again.