Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bin/crypt] can't open already open things

  • Loading branch information...
commit 7132e8509553e6e4ed78302af2efa429b0e488eb 1 parent e0ac8d7
@masak authored
Showing with 35 additions and 1 deletion.
  1. +35 −1 bin/crypt
View
36 bin/crypt
@@ -306,6 +306,14 @@ class X::Adventure::ThingNotOpenable is X::Adventure {
}
}
+class X::Adventure::ThingAlreadyOpen is X::Adventure {
+ has $.thing;
+
+ method message {
+ "The $.thing is open"
+ }
+}
+
class Adventure::Engine {
my @possible_directions = <
north south east west
@@ -321,6 +329,7 @@ class Adventure::Engine {
has %!try_exit_hooks;
has %!thing_rooms;
has %!openable_things;
+ has %!open_things;
method connect(@rooms, $direction) {
die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -417,7 +426,12 @@ class Adventure::Engine {
die X::Adventure::ThingNotOpenable.new(:$thing)
unless %!openable_things{$thing};
- Adventure::PlayerOpened.new(:$thing);
+ die X::Adventure::ThingAlreadyOpen.new(:$thing)
+ if %!open_things{$thing};
+
+ my @events = Adventure::PlayerOpened.new(:$thing);
+ self!apply($_) for @events;
+ @events;
}
method on_try_exit($room, $direction, &hook) {
@@ -474,6 +488,9 @@ class Adventure::Engine {
when Adventure::ThingPlaced {
%!thing_rooms{.thing} = .room;
}
+ when Adventure::PlayerOpened {
+ %!open_things{.thing} = True;
+ }
}
}
@@ -959,6 +976,23 @@ multi MAIN('test') {
};
}
+ {
+ my $engine = Adventure::Engine.new();
+
+ $engine.place_thing('car', 'street');
+ $engine.make_thing_openable('car');
+ $engine.place_player('street');
+ $engine.open('car');
+ throws_exception
+ { $engine.open('car') },
+ X::Adventure::ThingAlreadyOpen,
+ 'opening an object (-) it is already open',
+ {
+ is .thing, 'car', '.thing attribute';
+ is .message, "The car is open", '.message attribute';
+ };
+ }
+
done;
}

0 comments on commit 7132e85

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