Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[bin/crypt] a flashlight and a rope in the car
And they're revealed when we open the car.
  • Loading branch information
Carl Masak committed Jul 17, 2012
1 parent fd3ee8c commit d570802
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion bin/crypt
Expand Up @@ -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 {
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand All @@ -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');
}
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit d570802

Please sign in to comment.