Skip to content

Commit

Permalink
[bin/crypt] looking now tells about exits
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Jul 8, 2012
1 parent 79f0763 commit c9841be
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions bin/crypt
Expand Up @@ -238,6 +238,7 @@ class Adventure::PlayerWasPlaced does Event {

class Adventure::PlayerLooked does Event {
has $.description_of;
has @.exits;
}

class Adventure::TwoRoomsConnected does Event {
Expand Down Expand Up @@ -315,22 +316,31 @@ class Adventure::Engine {

my @events = Adventure::PlayerWalked.new(:$to);
unless %!seen_room{$to}++ {
@events.push(Adventure::PlayerLooked.new(:description_of($to)));
@events.push(Adventure::PlayerLooked.new(
:description_of($to),
:exits(%!exits{$to}.keys),
));
}
self!apply($_) for @events;
@events;
}

method look() {
my @events = Adventure::PlayerLooked.new(:description_of($!player_location));
my @events = Adventure::PlayerLooked.new(
:description_of($!player_location),
:exits(%!exits($!player_location)),
);
self!apply($_) for @events;
@events;
}

method place_player($in) {
my @events = Adventure::PlayerWasPlaced.new(:$in);
unless %!seen_room{$in}++ {
@events.push(Adventure::PlayerLooked.new(:description_of($in)));
@events.push(Adventure::PlayerLooked.new(
:description_of($in),
:exits(%!exits{$in}.keys),
));
}
self!apply($_) for @events;
@events;
Expand Down Expand Up @@ -461,6 +471,7 @@ multi MAIN() {
say .ucfirst;
say "";
say %descriptions{$_};
say "You can go east.";
say "";
}

Expand Down Expand Up @@ -499,6 +510,9 @@ multi MAIN() {
say ucfirst .description_of;
say "";
say %descriptions{.description_of};
if .exits {
say "You can go {join ' and ', .exits}.";
}
}
}
}
Expand All @@ -521,6 +535,9 @@ multi MAIN() {
when Adventure::PlayerWalked { say ucfirst .to; say "" }
when Adventure::PlayerLooked {
say %descriptions{.description_of};
if .exits {
say "You can go {join ' and ', .exits}.";
}
}
}
CATCH {
Expand Down

0 comments on commit c9841be

Please sign in to comment.