Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] implicit things not listed

  • Loading branch information...
commit af694afa26008e8b50d8aeb872257a1f85761503 1 parent d807669
Carl Mäsak authored July 16, 2012

Showing 1 changed file with 34 additions and 5 deletions. Show diff stats Hide diff stats

  1. 39  bin/crypt
39  bin/crypt
@@ -316,6 +316,10 @@ class Adventure::PlayerDropped does Event {
316 316
     has $.thing;
317 317
 }
318 318
 
  319
+class Adventure::ThingMadeImplicit does Event {
  320
+    has $.thing;
  321
+}
  322
+
319 323
 class X::Adventure is Exception {
320 324
 }
321 325
 
@@ -445,6 +449,7 @@ class Adventure::Engine {
445 449
     has %!hidden_things;
446 450
     has %!examine_hooks;
447 451
     has %!carryable_things;
  452
+    has %!implicit_things;
448 453
 
449 454
     method connect(@rooms, $direction) {
450 455
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -454,9 +459,12 @@ class Adventure::Engine {
454 459
         self!apply_and_return: @events;
455 460
     }
456 461
 
457  
-    method !things_here {
  462
+    method !explicit_things_here {
458 463
         return unless $!player_location;
459  
-        return %!thing_rooms.grep({ .value eq $!player_location })>>.key;
  464
+        sub is_here_and_explicit($_) {
  465
+            %!thing_rooms{$_} eq $!player_location && !%!implicit_things{$_}
  466
+        }
  467
+        return %!thing_rooms.keys.grep(&is_here_and_explicit);
460 468
     }
461 469
 
462 470
     method walk($direction) {
@@ -483,7 +491,7 @@ class Adventure::Engine {
483 491
             @events.push(Adventure::PlayerLooked.new(
484 492
                 :room($to),
485 493
                 :exits((%!exits{$to} // ()).keys),
486  
-                :things(self!things_here),
  494
+                :things(self!explicit_things_here),
487 495
             ));
488 496
         }
489 497
         self!apply_and_return: @events;
@@ -496,7 +504,7 @@ class Adventure::Engine {
496 504
         my @events = Adventure::PlayerLooked.new(
497 505
             :room($!player_location),
498 506
             :exits((%!exits{$!player_location} // ()).keys),
499  
-            :things(self!things_here),
  507
+            :things(self!explicit_things_here),
500 508
         );
501 509
         self!apply_and_return: @events;
502 510
     }
@@ -507,7 +515,7 @@ class Adventure::Engine {
507 515
             @events.push(Adventure::PlayerLooked.new(
508 516
                 :room($in),
509 517
                 :exits((%!exits{$in} // ()).keys),
510  
-                :things(self!things_here),
  518
+                :things(self!explicit_things_here),
511 519
             ));
512 520
         }
513 521
         self!apply_and_return: @events;
@@ -685,6 +693,11 @@ class Adventure::Engine {
685 693
         self!apply_and_return: @events;
686 694
     }
687 695
 
  696
+    method make_thing_implicit($thing) {
  697
+        my @events = Adventure::ThingMadeImplicit.new(:$thing);
  698
+        self!apply_and_return: @events;
  699
+    }
  700
+
688 701
     method on_try_exit($room, $direction, &hook) {
689 702
         %!try_exit_hooks{$room}{$direction} = &hook;
690 703
     }
@@ -775,6 +788,9 @@ class Adventure::Engine {
775 788
         when Adventure::PlayerDropped {
776 789
             %!thing_rooms{.thing} = $!player_location;
777 790
         }
  791
+        when Adventure::ThingMadeImplicit {
  792
+            %!implicit_things{.thing} = True;
  793
+        }
778 794
     }
779 795
 }
780 796
 
@@ -1638,6 +1654,19 @@ multi MAIN('test') {
1638 1654
             'looking at the room, explicit thing';
1639 1655
     }
1640 1656
 
  1657
+    {
  1658
+        my $engine = Adventure::Engine.new();
  1659
+
  1660
+        $engine.place_thing('fog', 'street');
  1661
+        $engine.make_thing_implicit('fog');
  1662
+        $engine.place_player('street');
  1663
+        is $engine.look(),
  1664
+            Adventure::PlayerLooked.new(
  1665
+                :room<street>,
  1666
+            ),
  1667
+            'looking at the room, implicit thing';
  1668
+    }
  1669
+
1641 1670
     done;
1642 1671
 }
1643 1672
 

0 notes on commit af694af

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