Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bin/crypt] can't take non-carryable things

  • Loading branch information...
commit 9a88a7ff57537a5cd1fa89c3ba26e9ed67af1611 1 parent c632483
Carl Mäsak authored
Showing with 41 additions and 0 deletions.
  1. +41 −0 bin/crypt
41 bin/crypt
View
@@ -305,6 +305,10 @@ class Adventure::PlayerTook does Event {
has $.thing;
}
+class Adventure::ThingMadeCarryable does Event {
+ has $.thing;
+}
+
class X::Adventure is Exception {
}
@@ -387,6 +391,15 @@ class X::Adventure::ThingNotReadable is X::Adventure {
}
}
+class X::Adventure::ThingNotCarryable is X::Adventure {
+ has $.action;
+ has $.thing;
+
+ method message {
+ "You cannot $.action the $.thing"
+ }
+}
+
class Adventure::Engine {
my @possible_directions = <
north south east west
@@ -408,6 +421,7 @@ class Adventure::Engine {
has %!readable_things;
has %!hidden_things;
has %!examine_hooks;
+ has %!carryable_things;
method connect(@rooms, $direction) {
die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -608,9 +622,15 @@ class Adventure::Engine {
}
method make_thing_carryable($thing) {
+ my @events = Adventure::ThingMadeCarryable.new(:$thing);
+ self!apply($_) for @events;
+ @events;
}
method take($thing) {
+ die X::Adventure::ThingNotCarryable.new(:action<take>, :$thing)
+ unless %!carryable_things{$thing};
+
my @events = Adventure::PlayerTook.new(:$thing);
self!apply($_) for @events;
@events;
@@ -692,6 +712,9 @@ class Adventure::Engine {
when Adventure::ThingUnhidden {
%!hidden_things{.thing} = False;
}
+ when Adventure::ThingMadeCarryable {
+ %!carryable_things{.thing} = True;
+ }
}
}
@@ -1415,6 +1438,24 @@ multi MAIN('test') {
'taking a thing (+)';
}
+ {
+ my $engine = Adventure::Engine.new();
+
+ $engine.place_thing('table', 'saloon');
+ # don't make table carryable
+ throws_exception
+ { $engine.take('table') },
+ X::Adventure::ThingNotCarryable,
+ 'taking a thing (-) it is not carryable',
+ {
+ is .action, 'take', '.action attribute';
+ is .thing, 'table', '.thing attribute';
+ is .message,
+ "You cannot take the table",
+ '.message attribute';
+ };
+ }
+
done;
}
Please sign in to comment.
Something went wrong with that request. Please try again.