Skip to content

Commit

Permalink
[bin/crypt] hole opens and closes based on hanoi
Browse files Browse the repository at this point in the history
Tradeoffs, they're everywhere. But it works.
  • Loading branch information
Carl Masak committed Jul 23, 2012
1 parent 3d9700e commit 69d6d84
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
35 changes: 34 additions & 1 deletion bin/crypt
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ class Adventure::TwoRoomsConnected does Event {
has $.direction; has $.direction;
} }


class Adventure::TwoRoomsDisconnected does Event {
has @.rooms;
has $.direction;
}

class Adventure::DirectionAliased does Event { class Adventure::DirectionAliased does Event {
has $.room; has $.room;
has $.direction; has $.direction;
Expand Down Expand Up @@ -492,6 +497,14 @@ class Adventure::Engine {
self!apply_and_return: @events; self!apply_and_return: @events;
} }


method disconnect(@rooms, $direction) {
die X::Adventure::NoSuchDirection.new(:action('disconnect rooms'), :$direction)
unless $direction eq any(@possible_directions);

my @events = Adventure::TwoRoomsDisconnected.new(:@rooms, :$direction);
self!apply_and_return: @events;
}

method !contents_of($thing) { method !contents_of($thing) {
return %!thing_rooms.grep({.value eq "contents:$thing"})>>.key; return %!thing_rooms.grep({.value eq "contents:$thing"})>>.key;
} }
Expand Down Expand Up @@ -891,6 +904,12 @@ class Adventure::Engine {
%!exits{$room1}{$direction} = $room2; %!exits{$room1}{$direction} = $room2;
%!exits{$room2}{opposite $direction} = $room1; %!exits{$room2}{opposite $direction} = $room1;
} }
when Adventure::TwoRoomsDisconnected {
my ($room1, $room2) = .rooms.list;
my $direction = .direction;
%!exits{$room1}.delete($direction);
%!exits{$room2}.delete(opposite $direction);
}
when Adventure::PlayerWalked { when Adventure::PlayerWalked {
$!player_location = .to; $!player_location = .to;
} }
Expand Down Expand Up @@ -1078,7 +1097,20 @@ class Crypt::Game {
die X::Crypt::NoDisksHere.new die X::Crypt::NoDisksHere.new
unless $!player_location eq 'hall'; unless $!player_location eq 'hall';


return $!hanoi.move($source, $target); my @events = $!hanoi.move($source, $target);
for @events {
when Hanoi::AchievementUnlocked {
push @events,
$!engine.remark('floor-reveals-hole'),
$!engine.connect(<hall cave>, 'down');
}
when Hanoi::AchievementLocked {
push @events,
$!engine.remark('floor-hides-hole'),
$!engine.disconnect(<hall cave>, 'down');
}
}
return @events;
} }


method save { method save {
Expand Down Expand Up @@ -1287,6 +1319,7 @@ multi MAIN() {
} }
CATCH { CATCH {
when X::Adventure { say .message, '.' } when X::Adventure { say .message, '.' }
when X::Hanoi { say .message, '.' }
} }
} }


Expand Down
6 changes: 6 additions & 0 deletions game-data/descriptions
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ You discover a door in the hill, under the thick grass!
== remark:passageway-opens-up == remark:passageway-opens-up
The ground rumbles and shakes a bit. The ground rumbles and shakes a bit.
A passageway opens up to the south, into the caverns. A passageway opens up to the south, into the caverns.

== remark:floor-reveals-hole
The whole floor tips, and reveals a hole beneath the wall.

== remark:floor-hides-hole
The whole floor tips back, hiding the hole again.

0 comments on commit 69d6d84

Please sign in to comment.