Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[bin/crypt] PlayerLooked includes list of things

  • Loading branch information...
commit d807669a4a8e780a964b6bdae00f01c0ed989cc4 1 parent e5c5198
@masak authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 bin/crypt
View
22 bin/crypt
@@ -243,6 +243,7 @@ class Adventure::PlayerWasPlaced does Event {
class Adventure::PlayerLooked does Event {
has $.room;
has @.exits;
+ has @.things;
}
class Adventure::TwoRoomsConnected does Event {
@@ -453,6 +454,11 @@ class Adventure::Engine {
self!apply_and_return: @events;
}
+ method !things_here {
+ return unless $!player_location;
+ return %!thing_rooms.grep({ .value eq $!player_location })>>.key;
+ }
+
method walk($direction) {
die X::Adventure::PlayerNowhere.new()
unless defined $!player_location;
@@ -477,6 +483,7 @@ class Adventure::Engine {
@events.push(Adventure::PlayerLooked.new(
:room($to),
:exits((%!exits{$to} // ()).keys),
+ :things(self!things_here),
));
}
self!apply_and_return: @events;
@@ -489,6 +496,7 @@ class Adventure::Engine {
my @events = Adventure::PlayerLooked.new(
:room($!player_location),
:exits((%!exits{$!player_location} // ()).keys),
+ :things(self!things_here),
);
self!apply_and_return: @events;
}
@@ -499,6 +507,7 @@ class Adventure::Engine {
@events.push(Adventure::PlayerLooked.new(
:room($in),
:exits((%!exits{$in} // ()).keys),
+ :things(self!things_here),
));
}
self!apply_and_return: @events;
@@ -1616,6 +1625,19 @@ multi MAIN('test') {
'taking a thing (+) take, drop, take';
}
+ {
+ my $engine = Adventure::Engine.new();
+
+ $engine.place_thing('dog', 'street');
+ $engine.place_player('street');
+ is $engine.look(),
+ Adventure::PlayerLooked.new(
+ :room<street>,
+ :things<dog>,
+ ),
+ 'looking at the room, explicit thing';
+ }
+
done;
}
Please sign in to comment.
Something went wrong with that request. Please try again.