Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bin/crypt] a flashlight and a rope in the car

And they're revealed when we open the car.
  • Loading branch information...
commit d570802f689a8609df2d4c9ba53a26dbad236db6 1 parent fd3ee8c
@masak authored
Showing with 37 additions and 1 deletion.
  1. +37 −1 bin/crypt
View
38 bin/crypt
@@ -320,6 +320,11 @@ class Adventure::ThingMadeImplicit does Event {
has $.thing;
}
+class Adventure::ContentsRevealed does Event {
+ has $.container;
+ has @.contents;
+}
+
class X::Adventure is Exception {
}
@@ -467,6 +472,10 @@ class Adventure::Engine {
return %!thing_rooms.keys.grep(&is_here_and_explicit);
}
+ method !contents_of($thing) {
+ return %!thing_rooms.grep({.value eq "contents:$thing"})>>.key;
+ }
+
method walk($direction) {
die X::Adventure::PlayerNowhere.new()
unless defined $!player_location;
@@ -576,6 +585,14 @@ class Adventure::Engine {
if %!open_things{$thing};
my @events = Adventure::PlayerOpened.new(:$thing);
+ my @contents = self!contents_of($thing);
+ if @contents {
+ @events.push(
+ Adventure::ContentsRevealed.new(
+ :container($thing), :@contents
+ )
+ );
+ }
self!apply_and_return: @events;
}
@@ -795,7 +812,7 @@ class Adventure::Engine {
}
class Crypt::Game {
- has $!engine handles <walk save>;
+ has $!engine handles <walk save open>;
submethod BUILD() {
$!engine = Adventure::Engine.new();
@@ -812,6 +829,9 @@ class Crypt::Game {
False;
});
.place_thing('car', 'clearing');
+ .place_thing('flashlight', 'contents:car');
+ .place_thing('rope', 'contents:car');
+ .make_thing_openable('car');
.place_player('clearing');
}
}
@@ -1669,6 +1689,22 @@ multi MAIN('test') {
'looking at the room, implicit thing';
}
+ {
+ my $game = Crypt::Game.new();
+
+ is $game.open('car'),
+ [
+ Adventure::PlayerOpened.new(
+ :thing<car>,
+ ),
+ Adventure::ContentsRevealed.new(
+ :container<car>,
+ :contents<flashlight rope>,
+ ),
+ ],
+ 'opening the car';
+ }
+
done;
}
Please sign in to comment.
Something went wrong with that request. Please try again.