Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bin/crypt] room connections now go both ways

  • Loading branch information...
commit 9a7f528d5b92e1659cfa32c12f43a9b21581a6cf 1 parent e478ae2
@masak authored
Showing with 30 additions and 0 deletions.
  1. +30 −0 bin/crypt
View
30 bin/crypt
@@ -326,12 +326,28 @@ class Adventure::Engine {
@events;
}
+ sub opposite($direction) {
+ my %opposites =
+ 'north' => 'south',
+ 'east' => 'west',
+ 'northeast' => 'southwest',
+ 'northwest' => 'southeast',
+ 'up' => 'down',
+ 'in' => 'out',
+ ;
+
+ %opposites.push( %opposites.invert );
+
+ %opposites{$direction};
+ }
+
# RAKUDO: private multimethods NYI
method !apply(Event $_) {
when Adventure::TwoRoomsConnected {
my ($room1, $room2) = .rooms.list;
my $direction = .direction;
%!exits{$room1}{$direction} = $room2;
+ %!exits{$room2}{opposite $direction} = $room1;
}
when Adventure::PlayerWalked {
$!player_location = .to;
@@ -701,6 +717,20 @@ multi MAIN('test') {
'going inside now means going southwest';
}
+ {
+ my $engine = Adventure::Engine.new();
+
+ my @rooms = <kitchen veranda>;
+ $engine.connect(@rooms, my $direction = 'south');
+ $engine.place_player('kitchen');
+ $engine.walk('south');
+ is $engine.walk('north'),
+ Adventure::PlayerWalked.new(
+ :to<kitchen>,
+ ),
+ 'connecting two rooms creates a mutual connection';
+ }
+
done;
}
Please sign in to comment.
Something went wrong with that request. Please try again.