Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] room connections now go both ways

  • Loading branch information...
commit 9a7f528d5b92e1659cfa32c12f43a9b21581a6cf 1 parent e478ae2
Carl Mäsak authored July 06, 2012

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

  1. 30  bin/crypt
30  bin/crypt
@@ -326,12 +326,28 @@ class Adventure::Engine {
326 326
         @events;
327 327
     }
328 328
 
  329
+    sub opposite($direction) {
  330
+        my %opposites =
  331
+            'north'     => 'south',
  332
+            'east'      => 'west',
  333
+            'northeast' => 'southwest',
  334
+            'northwest' => 'southeast',
  335
+            'up'        => 'down',
  336
+            'in'        => 'out',
  337
+        ;
  338
+
  339
+        %opposites.push( %opposites.invert );
  340
+
  341
+        %opposites{$direction};
  342
+    }
  343
+
329 344
     # RAKUDO: private multimethods NYI
330 345
     method !apply(Event $_) {
331 346
         when Adventure::TwoRoomsConnected {
332 347
             my ($room1, $room2) = .rooms.list;
333 348
             my $direction = .direction;
334 349
             %!exits{$room1}{$direction} = $room2;
  350
+            %!exits{$room2}{opposite $direction} = $room1;
335 351
         }
336 352
         when Adventure::PlayerWalked {
337 353
             $!player_location = .to;
@@ -701,6 +717,20 @@ multi MAIN('test') {
701 717
             'going inside now means going southwest';
702 718
     }
703 719
 
  720
+    {
  721
+        my $engine = Adventure::Engine.new();
  722
+
  723
+        my @rooms = <kitchen veranda>;
  724
+        $engine.connect(@rooms, my $direction = 'south');
  725
+        $engine.place_player('kitchen');
  726
+        $engine.walk('south');
  727
+        is $engine.walk('north'),
  728
+            Adventure::PlayerWalked.new(
  729
+                :to<kitchen>,
  730
+            ),
  731
+            'connecting two rooms creates a mutual connection';
  732
+    }
  733
+
704 734
     done;
705 735
 }
706 736
 

0 notes on commit 9a7f528

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