Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] hole opens and closes based on hanoi

Tradeoffs, they're everywhere. But it works.
  • Loading branch information...
commit 69d6d841ae49c81160b91e45d12da9075740cf36 1 parent 3d9700e
Carl Mäsak authored
35  bin/crypt
@@ -251,6 +251,11 @@ class Adventure::TwoRoomsConnected does Event {
251 251
     has $.direction;
252 252
 }
253 253
 
  254
+class Adventure::TwoRoomsDisconnected does Event {
  255
+    has @.rooms;
  256
+    has $.direction;
  257
+}
  258
+
254 259
 class Adventure::DirectionAliased does Event {
255 260
     has $.room;
256 261
     has $.direction;
@@ -492,6 +497,14 @@ class Adventure::Engine {
492 497
         self!apply_and_return: @events;
493 498
     }
494 499
 
  500
+    method disconnect(@rooms, $direction) {
  501
+        die X::Adventure::NoSuchDirection.new(:action('disconnect rooms'), :$direction)
  502
+            unless $direction eq any(@possible_directions);
  503
+
  504
+        my @events = Adventure::TwoRoomsDisconnected.new(:@rooms, :$direction);
  505
+        self!apply_and_return: @events;
  506
+    }
  507
+
495 508
     method !contents_of($thing) {
496 509
         return %!thing_rooms.grep({.value eq "contents:$thing"})>>.key;
497 510
     }
@@ -891,6 +904,12 @@ class Adventure::Engine {
891 904
             %!exits{$room1}{$direction} = $room2;
892 905
             %!exits{$room2}{opposite $direction} = $room1;
893 906
         }
  907
+        when Adventure::TwoRoomsDisconnected {
  908
+            my ($room1, $room2) = .rooms.list;
  909
+            my $direction = .direction;
  910
+            %!exits{$room1}.delete($direction);
  911
+            %!exits{$room2}.delete(opposite $direction);
  912
+        }
894 913
         when Adventure::PlayerWalked {
895 914
             $!player_location = .to;
896 915
         }
@@ -1078,7 +1097,20 @@ class Crypt::Game {
1078 1097
         die X::Crypt::NoDisksHere.new
1079 1098
             unless $!player_location eq 'hall';
1080 1099
 
1081  
-        return $!hanoi.move($source, $target);
  1100
+        my @events = $!hanoi.move($source, $target);
  1101
+        for @events {
  1102
+            when Hanoi::AchievementUnlocked {
  1103
+                push @events,
  1104
+                    $!engine.remark('floor-reveals-hole'),
  1105
+                    $!engine.connect(<hall cave>, 'down');
  1106
+            }
  1107
+            when Hanoi::AchievementLocked {
  1108
+                push @events,
  1109
+                    $!engine.remark('floor-hides-hole'),
  1110
+                    $!engine.disconnect(<hall cave>, 'down');
  1111
+            }
  1112
+        }
  1113
+        return @events;
1082 1114
     }
1083 1115
 
1084 1116
     method save {
@@ -1287,6 +1319,7 @@ multi MAIN() {
1287 1319
                 }
1288 1320
                 CATCH {
1289 1321
                     when X::Adventure { say .message, '.' }
  1322
+                    when X::Hanoi { say .message, '.' }
1290 1323
                 }
1291 1324
             }
1292 1325
 
6  game-data/descriptions
@@ -71,3 +71,9 @@ You discover a door in the hill, under the thick grass!
71 71
 == remark:passageway-opens-up
72 72
 The ground rumbles and shakes a bit.
73 73
 A passageway opens up to the south, into the caverns.
  74
+
  75
+== remark:floor-reveals-hole
  76
+The whole floor tips, and reveals a hole beneath the wall.
  77
+
  78
+== remark:floor-hides-hole
  79
+The whole floor tips back, hiding the hole again.

0 notes on commit 69d6d84

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