Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit ecf3cabe62314a44460b0bfb228e62e668336425 1 parent e4f2c0c
Carl Mäsak authored July 24, 2012

Showing 1 changed file with 29 additions and 0 deletions. Show diff stats Hide diff stats

  1. 29  bin/crypt
29  bin/crypt
@@ -460,6 +460,14 @@ class X::Adventure::PlayerDoesNotHave is X::Adventure {
460 460
     }
461 461
 }
462 462
 
  463
+class X::Adventure::PitchBlack is X::Adventure {
  464
+    has $.action;
  465
+
  466
+    method message {
  467
+        "You cannot $.action anything, because it is pitch black"
  468
+    }
  469
+}
  470
+
463 471
 class Adventure::Engine {
464 472
     my @possible_directions = <
465 473
         north south east west
@@ -791,6 +799,12 @@ class Adventure::Engine {
791 799
         die X::Adventure::PlayerAlreadyCarries.new(:$thing)
792 800
             if (%!thing_rooms{$thing} // '') eq 'player inventory';
793 801
 
  802
+        my $pitch_black = %!dark_rooms{$!player_location}
  803
+            && !self!shining_thing_here($!player_location);
  804
+
  805
+        die X::Adventure::PitchBlack.new(:action<take>)
  806
+            if $pitch_black;
  807
+
794 808
         die X::Adventure::NoSuchThingHere.new(:$thing)
795 809
             unless self!is_thing_in($thing, $!player_location);
796 810
 
@@ -2354,6 +2368,21 @@ multi MAIN('test') {
2354 2368
             'taking the helmet (+)';
2355 2369
     }
2356 2370
 
  2371
+    {
  2372
+        my $game = game_from_hall();
  2373
+
  2374
+        throws_exception
  2375
+            { $game.take('helmet') },
  2376
+            X::Adventure::PitchBlack,
  2377
+            'taking the helmet (-) pitch black',
  2378
+            {
  2379
+                is .action, 'take', '.action attribute';
  2380
+                is .message,
  2381
+                    "You cannot take anything, because it is pitch black",
  2382
+                    '.message attribute';
  2383
+            };
  2384
+    }
  2385
+
2357 2386
     done;
2358 2387
 }
2359 2388
 

0 notes on commit ecf3cab

Please sign in to comment.
Something went wrong with that request. Please try again.