Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] opening the door causes exit to appear

  • Loading branch information...
commit 27722eec71fb8f5528f41aeb6e4809760c151792 1 parent dcd529a
Carl Mäsak authored July 18, 2012

Showing 1 changed file with 13 additions and 7 deletions. Show diff stats Hide diff stats

  1. 20  bin/crypt
20  bin/crypt
@@ -455,6 +455,7 @@ class Adventure::Engine {
455 455
     has %!examine_hooks;
456 456
     has %!carryable_things;
457 457
     has %!implicit_things;
  458
+    has %!open_hooks;
458 459
 
459 460
     method connect(@rooms, $direction) {
460 461
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -615,6 +616,9 @@ class Adventure::Engine {
615 616
                 )
616 617
             );
617 618
         }
  619
+        if %!open_hooks{$thing} -> &hook {
  620
+            @events.push(&hook());
  621
+        }
618 622
         self!apply_and_return: @events;
619 623
     }
620 624
 
@@ -746,6 +750,10 @@ class Adventure::Engine {
746 750
         %!examine_hooks{$thing} = &hook;
747 751
     }
748 752
 
  753
+    method on_open($thing, &hook) {
  754
+        %!open_hooks{$thing} = &hook;
  755
+    }
  756
+
749 757
     my class Save {
750 758
         has @.events;
751 759
     }
@@ -871,11 +879,9 @@ class Crypt::Game {
871 879
             .place_thing('door', 'hill');
872 880
             .make_thing_openable('door');
873 881
             .hide_thing('door');
874  
-            .on_examine('grass', { $!engine.unhide_thing('door') });
875  
-            .on_examine('bushes', { $!engine.unhide_thing('door') });
876  
-
877  
-            # yes, this is cheat. will fix in the next commit.
878  
-            .connect(<hill chamber>, 'south');
  882
+            .on_examine('grass', { .unhide_thing('door') });
  883
+            .on_examine('bushes', { .unhide_thing('door') });
  884
+            .on_open('door', { .connect(<hill chamber>, 'south') });
879 885
 
880 886
             .place_player('clearing');
881 887
         }
@@ -1848,7 +1854,7 @@ multi MAIN('test') {
1848 1854
 
1849 1855
         $game.walk('east');
1850 1856
         $game.examine('grass');
1851  
-        is $game.open('door'),
  1857
+        is $game.open('door')[0],
1852 1858
             Adventure::PlayerOpened.new(
1853 1859
                 :thing<door>,
1854 1860
             ),
@@ -1870,7 +1876,7 @@ multi MAIN('test') {
1870 1876
 
1871 1877
         $game.walk('east');
1872 1878
         $game.examine('bushes');
1873  
-        is $game.open('door'),
  1879
+        is $game.open('door')[0],
1874 1880
             Adventure::PlayerOpened.new(
1875 1881
                 :thing<door>,
1876 1882
             ),

0 notes on commit 27722ee

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