Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] hidden things can not be seen

  • Loading branch information...
commit 2bfc22dac7e42e059867fceac82577e820dad715 1 parent 1744ffd
Carl Mäsak authored July 14, 2012

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

  1. 29  bin/crypt
29  bin/crypt
@@ -291,6 +291,10 @@ class Adventure::ThingMadeReadable does Event {
291 291
     has $.thing;
292 292
 }
293 293
 
  294
+class Adventure::ThingHidden does Event {
  295
+    has $.thing;
  296
+}
  297
+
294 298
 class X::Adventure is Exception {
295 299
 }
296 300
 
@@ -392,6 +396,7 @@ class Adventure::Engine {
392 396
     has %!containers;
393 397
     has %!platforms;
394 398
     has %!readable_things;
  399
+    has %!hidden_things;
395 400
 
396 401
     method connect(@rooms, $direction) {
397 402
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -479,6 +484,9 @@ class Adventure::Engine {
479 484
         die X::Adventure::NoSuchThingHere.new(:$thing)
480 485
             unless (%!thing_rooms{$thing} // '') eq $!player_location;
481 486
 
  487
+        die X::Adventure::NoSuchThingHere.new(:$thing)
  488
+            if %!hidden_things{$thing};
  489
+
482 490
         my @events = Adventure::PlayerExamined.new(
483 491
             :$thing
484 492
         );
@@ -566,6 +574,12 @@ class Adventure::Engine {
566 574
         Adventure::PlayerRead.new(:$thing);
567 575
     }
568 576
 
  577
+    method hide_thing($thing) {
  578
+        my @events = Adventure::ThingHidden.new(:$thing);
  579
+        self!apply($_) for @events;
  580
+        @events;
  581
+    }
  582
+
569 583
     method on_try_exit($room, $direction, &hook) {
570 584
         %!try_exit_hooks{$room}{$direction} = &hook;
571 585
     }
@@ -632,6 +646,9 @@ class Adventure::Engine {
632 646
         when Adventure::ThingMadeReadable {
633 647
             %!readable_things{.thing} = True;
634 648
         }
  649
+        when Adventure::ThingHidden {
  650
+            %!hidden_things{.thing} = True;
  651
+        }
635 652
     }
636 653
 }
637 654
 
@@ -1292,6 +1309,18 @@ multi MAIN('test') {
1292 1309
             };
1293 1310
     }
1294 1311
 
  1312
+    {
  1313
+        my $engine = Adventure::Engine.new();
  1314
+
  1315
+        $engine.place_thing('flask', 'chamber');
  1316
+        $engine.hide_thing('flask');
  1317
+        $engine.place_player('chamber');
  1318
+        throws_exception
  1319
+            { $engine.examine('flask') },
  1320
+            X::Adventure::NoSuchThingHere,
  1321
+            'examining a hidden thing (-) cannot because it is hidden';
  1322
+    }
  1323
+
1295 1324
     done;
1296 1325
 }
1297 1326
 

0 notes on commit 2bfc22d

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