Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] winning the game

  • Loading branch information...
commit e3b2633181a2e2f02592496304ce55a559521fb1 1 parent 07222ec
Carl Mäsak authored July 28, 2012
86  bin/crypt
@@ -601,27 +601,32 @@ class Adventure::Engine {
601 601
         die X::Adventure::NoExitThere.new(:$direction)
602 602
             unless defined $to;
603 603
 
  604
+        my @events;
  605
+        my $walk = True;
604 606
         if %!try_exit_hooks{$!player_location}{$actual_direction} -> &hook {
605  
-            return unless &hook();
  607
+            @events.push(&hook());
  608
+            $walk = @events.pop;
606 609
         }
607 610
 
608  
-        my @events = Adventure::PlayerWalked.new(:$to);
609  
-        unless %!seen_room{$to}++ {
610  
-            my $pitch_black = %!dark_rooms{$to}
611  
-                && !self!shining_thing_here($to);
  611
+        if $walk {
  612
+            @events.push(Adventure::PlayerWalked.new(:$to));
  613
+            unless %!seen_room{$to}++ {
  614
+                my $pitch_black = %!dark_rooms{$to}
  615
+                    && !self!shining_thing_here($to);
612 616
 
613  
-            if $pitch_black {
614  
-                @events.push(Adventure::PlayerLookedAtDarkness.new());
615  
-            }
616  
-            else {
617  
-                @events.push(Adventure::PlayerLooked.new(
618  
-                    :room($to),
619  
-                    :exits((%!exits{$to} // ()).keys),
620  
-                    :things(self!explicit_things_at($to)),
621  
-                ));
  617
+                if $pitch_black {
  618
+                    @events.push(Adventure::PlayerLookedAtDarkness.new());
  619
+                }
  620
+                else {
  621
+                    @events.push(Adventure::PlayerLooked.new(
  622
+                        :room($to),
  623
+                        :exits((%!exits{$to} // ()).keys),
  624
+                        :things(self!explicit_things_at($to)),
  625
+                    ));
  626
+                }
622 627
             }
  628
+            @events.push(self!tick);
623 629
         }
624  
-        @events.push(self!tick);
625 630
         self!apply_and_return: @events;
626 631
     }
627 632
 
@@ -1106,6 +1111,16 @@ class Crypt::Game {
1106 1111
             .connect: <clearing hill>, 'east';
1107 1112
             .alias_direction: 'hill', 'in', 'south';
1108 1113
             .alias_direction: 'chamber', 'out', 'north';
  1114
+            .on_try_exit: 'chamber', 'north', {
  1115
+                if .thing_is_in('butterfly', 'player inventory') {
  1116
+                    .remark('made-it-out-with-treasure'),
  1117
+                    .finish(),
  1118
+                    False;
  1119
+                }
  1120
+                else {
  1121
+                    True;
  1122
+                }
  1123
+            };
1109 1124
             .alias_direction: 'chamber', 'in', 'south';
1110 1125
             .alias_direction: 'hall', 'out', 'north';
1111 1126
             .connect: <cave crypt>, 'northwest';
@@ -1211,10 +1226,20 @@ class Crypt::Game {
1211 1226
             # Things in crypt
1212 1227
             .place_thing: 'pedestal', 'crypt';
1213 1228
             .make_thing_a_platform: 'pedestal';
  1229
+            .on_put:
  1230
+                'pedestal',
  1231
+                -> $_ {
  1232
+                    when 'butterfly' | 'tiny disk' {
  1233
+                        # XXX: Need to change signature of .put_out_fuse to
  1234
+                        # accept a closure, to be run if there was a fuse to
  1235
+                        # put out.
  1236
+                        $!engine.put_out_fuse('cavern-collapse');
  1237
+                    }
  1238
+                };
1214 1239
             .on_remove_from:
1215 1240
                 'pedestal',
1216 1241
                 -> $_ {
1217  
-                    when 'butterfly' | 'small disk' {
  1242
+                    when 'butterfly' | 'tiny disk' {
1218 1243
                         # XXX: Should be 3, will fix when getting sagas
1219 1244
                         $!engine.light_fuse(4, 'cavern-collapse', {
1220 1245
                             $!engine.remark('cavern-collapses'),
@@ -2686,7 +2711,7 @@ multi MAIN('test') {
2686 2711
             'putting out the fire with water';
2687 2712
     }
2688 2713
 
2689  
-    sub game_after_putting_out_the_water {
  2714
+    sub game_after_putting_out_the_fire {
2690 2715
         my $game = game_after_hanoi_is_solved();
2691 2716
 
2692 2717
         $game.take('helmet');
@@ -2701,7 +2726,7 @@ multi MAIN('test') {
2701 2726
     }
2702 2727
 
2703 2728
     {
2704  
-        my $game = game_after_putting_out_the_water();
  2729
+        my $game = game_after_putting_out_the_fire();
2705 2730
 
2706 2731
         is $game.walk('northwest')[0],
2707 2732
             Adventure::PlayerWalked.new(
@@ -2773,7 +2798,7 @@ multi MAIN('test') {
2773 2798
     }
2774 2799
 
2775 2800
     sub game_from_crypt {
2776  
-        my $game = game_after_putting_out_the_water();
  2801
+        my $game = game_after_putting_out_the_fire();
2777 2802
 
2778 2803
         $game.walk('northwest');
2779 2804
         return $game;
@@ -2835,6 +2860,29 @@ multi MAIN('test') {
2835 2860
             'can take the tiny disk from the hanoi game';
2836 2861
     }
2837 2862
 
  2863
+    {
  2864
+        my $game = game_after_putting_out_the_fire();
  2865
+
  2866
+        $game.walk('up');
  2867
+        $game.take('tiny disk');
  2868
+        $game.walk('down');
  2869
+        $game.walk('northwest');
  2870
+        $game.take('butterfly');
  2871
+        $game.put_thing_on('tiny disk', 'pedestal');
  2872
+        $game.walk('southeast');
  2873
+        $game.walk('up');
  2874
+        $game.walk('north');
  2875
+        is $game.walk('north'),
  2876
+            [
  2877
+                Adventure::GameRemarked.new(
  2878
+                    :remark<made-it-out-with-treasure>,
  2879
+                ),
  2880
+                Adventure::GameFinished.new(
  2881
+                ),
  2882
+            ],
  2883
+            'making it out alive with the treasure';
  2884
+    }
  2885
+
2838 2886
     done;
2839 2887
 }
2840 2888
 
4  game-data/descriptions
@@ -106,3 +106,7 @@ An alarm starts sounding in the whole cavern.
106 106
 The alarm starts sounding louder.
107 107
 The whole cavern shakes, and falls in on itself.
108 108
 You die.
  109
+
  110
+== remark:made-it-out-with-treasure
  111
+Congratulations! You found the treasure and got out with it
  112
+alive!

0 notes on commit e3b2633

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