Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[bin/crypt] can't drop things not in inventory

  • Loading branch information...
commit bfdb3509216407c9dfbd1a338815a0ba621efcdf 1 parent a0b45bb
Carl Mäsak authored
Showing with 32 additions and 0 deletions.
  1. +32 −0 bin/crypt
32 bin/crypt
View
@@ -405,6 +405,7 @@ class X::Adventure::ThingNotCarryable is X::Adventure {
"You cannot $.action the $.thing"
}
}
+
class X::Adventure::PlayerAlreadyCarries is X::Adventure {
has $.thing;
@@ -413,6 +414,14 @@ class X::Adventure::PlayerAlreadyCarries is X::Adventure {
}
}
+class X::Adventure::PlayerDoesNotHave is X::Adventure {
+ has $.thing;
+
+ method message {
+ "You are not carrying the $.thing"
+ }
+}
+
class Adventure::Engine {
my @possible_directions = <
north south east west
@@ -657,6 +666,12 @@ class Adventure::Engine {
}
method drop($thing) {
+ die X::Adventure::PlayerNowhere.new()
+ unless defined $!player_location;
+
+ die X::Adventure::PlayerDoesNotHave.new(:$thing)
+ unless %!thing_rooms{$thing} eq 'player inventory';
+
my @events = Adventure::PlayerDropped.new(:$thing);
self!apply_and_return: @events;
}
@@ -1566,6 +1581,23 @@ multi MAIN('test') {
'dropping a thing (+)';
}
+ {
+ my $engine = Adventure::Engine.new();
+
+ $engine.place_thing('cup', 'porch');
+ $engine.make_thing_carryable('cup');
+ $engine.place_player('porch');
+ throws_exception
+ { $engine.drop('cup') },
+ X::Adventure::PlayerDoesNotHave,
+ 'dropping a thing (-) player does not have it',
+ {
+ is .thing, 'cup', '.thing attribute';
+ is .message, "You are not carrying the cup",
+ '.message attribute';
+ };
+ }
+
done;
}
Please sign in to comment.
Something went wrong with that request. Please try again.