Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit bfdb3509216407c9dfbd1a338815a0ba621efcdf 1 parent a0b45bb
Carl Mäsak authored July 15, 2012

Showing 1 changed file with 32 additions and 0 deletions. Show diff stats Hide diff stats

  1. 32  bin/crypt
32  bin/crypt
@@ -405,6 +405,7 @@ class X::Adventure::ThingNotCarryable is X::Adventure {
405 405
         "You cannot $.action the $.thing"
406 406
     }
407 407
 }
  408
+
408 409
 class X::Adventure::PlayerAlreadyCarries is X::Adventure {
409 410
     has $.thing;
410 411
 
@@ -413,6 +414,14 @@ class X::Adventure::PlayerAlreadyCarries is X::Adventure {
413 414
     }
414 415
 }
415 416
 
  417
+class X::Adventure::PlayerDoesNotHave is X::Adventure {
  418
+    has $.thing;
  419
+
  420
+    method message {
  421
+        "You are not carrying the $.thing"
  422
+    }
  423
+}
  424
+
416 425
 class Adventure::Engine {
417 426
     my @possible_directions = <
418 427
         north south east west
@@ -657,6 +666,12 @@ class Adventure::Engine {
657 666
     }
658 667
 
659 668
     method drop($thing) {
  669
+        die X::Adventure::PlayerNowhere.new()
  670
+            unless defined $!player_location;
  671
+
  672
+        die X::Adventure::PlayerDoesNotHave.new(:$thing)
  673
+            unless %!thing_rooms{$thing} eq 'player inventory';
  674
+
660 675
         my @events = Adventure::PlayerDropped.new(:$thing);
661 676
         self!apply_and_return: @events;
662 677
     }
@@ -1566,6 +1581,23 @@ multi MAIN('test') {
1566 1581
             'dropping a thing (+)';
1567 1582
     }
1568 1583
 
  1584
+    {
  1585
+        my $engine = Adventure::Engine.new();
  1586
+
  1587
+        $engine.place_thing('cup', 'porch');
  1588
+        $engine.make_thing_carryable('cup');
  1589
+        $engine.place_player('porch');
  1590
+        throws_exception
  1591
+            { $engine.drop('cup') },
  1592
+            X::Adventure::PlayerDoesNotHave,
  1593
+            'dropping a thing (-) player does not have it',
  1594
+            {
  1595
+                is .thing, 'cup', '.thing attribute';
  1596
+                is .message, "You are not carrying the cup",
  1597
+                    '.message attribute';
  1598
+            };
  1599
+    }
  1600
+
1569 1601
     done;
1570 1602
 }
1571 1603
 

0 notes on commit bfdb350

Please sign in to comment.
Something went wrong with that request. Please try again.