Skip to content

Commit

Permalink
[bin/crypt] add on_try_exit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Jul 8, 2012
1 parent c9841be commit 6759b92
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions bin/crypt
Expand Up @@ -289,6 +289,7 @@ class Adventure::Engine {
has %!exits; has %!exits;
has %!exit_aliases; has %!exit_aliases;
has %!seen_room; has %!seen_room;
has %!try_exit_hooks;


method connect(@rooms, $direction) { method connect(@rooms, $direction) {
die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction) die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
Expand All @@ -314,6 +315,10 @@ class Adventure::Engine {
die X::Adventure::NoExitThere.new(:$direction) die X::Adventure::NoExitThere.new(:$direction)
unless defined $to; unless defined $to;


if %!try_exit_hooks{$!player_location}{$actual_direction} -> &hook {
return unless &hook();
}

my @events = Adventure::PlayerWalked.new(:$to); my @events = Adventure::PlayerWalked.new(:$to);
unless %!seen_room{$to}++ { unless %!seen_room{$to}++ {
@events.push(Adventure::PlayerLooked.new( @events.push(Adventure::PlayerLooked.new(
Expand Down Expand Up @@ -354,6 +359,10 @@ class Adventure::Engine {
@events; @events;
} }


method on_try_exit($room, $direction, &hook) {
%!try_exit_hooks{$room}{$direction} = &hook;
}

my class Save { my class Save {
has @.events; has @.events;
} }
Expand Down Expand Up @@ -421,6 +430,10 @@ class Crypt::Game {
.connect(<chamber hall>, 'south'); .connect(<chamber hall>, 'south');
.connect(<hall cave>, 'down'); .connect(<hall cave>, 'down');
.connect(<cave crypt>, 'northwest'); .connect(<cave crypt>, 'northwest');
.on_try_exit('cave', 'northwest', {
say "You try to walk past the fire, but it's too hot!";
False;
});
.place_player('clearing'); .place_player('clearing');
} }
} }
Expand Down

0 comments on commit 6759b92

Please sign in to comment.