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 take flashlight w/o opening car

  • Loading branch information...
commit a309abbc97c17956f8466c6bbbb69d8d19bd4aad 1 parent 9f30403
Carl Mäsak authored

Showing 1 changed file with 33 additions and 7 deletions. Show diff stats Hide diff stats

  1. 40  bin/crypt
40  bin/crypt
@@ -473,7 +473,7 @@ class Adventure::Engine {
473 473
             %!thing_rooms{$_} eq $location && !%!implicit_things{$_}
474 474
         }
475 475
 
476  
-        return unless $!player_location;
  476
+        return unless $location;
477 477
         return gather for %!thing_rooms.keys -> $thing {
478 478
             next unless is_here_and_explicit($thing);
479 479
             if %!open_things{$thing} && self!contents_of($thing) {
@@ -485,6 +485,22 @@ class Adventure::Engine {
485 485
         }
486 486
     }
487 487
 
  488
+    method !is_thing_in($sought, $location) {
  489
+        sub is_here_and_explicit($_) {
  490
+            %!thing_rooms{$_} eq $location && !%!implicit_things{$_}
  491
+        }
  492
+
  493
+        return unless $location;
  494
+        for %!thing_rooms.keys -> $thing {
  495
+            next unless is_here_and_explicit($thing);
  496
+            return True if $thing eq $sought;
  497
+            if %!open_things{$thing} && self!contents_of($thing) {
  498
+                return True if self!is_thing_in($sought, "contents:$thing");
  499
+            }
  500
+        }
  501
+        return False;
  502
+    }
  503
+
488 504
     method walk($direction) {
489 505
         die X::Adventure::PlayerNowhere.new()
490 506
             unless defined $!player_location;
@@ -696,14 +712,15 @@ class Adventure::Engine {
696 712
         die X::Adventure::PlayerNowhere.new()
697 713
             unless defined $!player_location;
698 714
 
699  
-        # XXX: should check if the thing is there
  715
+        die X::Adventure::PlayerAlreadyCarries.new(:$thing)
  716
+            if %!thing_rooms{$thing} eq 'player inventory';
  717
+
  718
+        die X::Adventure::NoSuchThingHere.new(:$thing)
  719
+            unless self!is_thing_in($thing, $!player_location);
700 720
 
701 721
         die X::Adventure::ThingNotCarryable.new(:action<take>, :$thing)
702 722
             unless %!carryable_things{$thing};
703 723
 
704  
-        die X::Adventure::PlayerAlreadyCarries.new(:$thing)
705  
-            if %!thing_rooms{$thing} eq 'player inventory';
706  
-
707 724
         my @events = Adventure::PlayerTook.new(:$thing);
708 725
         self!apply_and_return: @events;
709 726
     }
@@ -1744,7 +1761,7 @@ multi MAIN('test') {
1744 1761
             Adventure::PlayerTook.new(
1745 1762
                 :thing<flashlight>,
1746 1763
             ),
1747  
-            'taking the flashlight from the car';
  1764
+            'taking the flashlight from the car (+)';
1748 1765
     }
1749 1766
 
1750 1767
     {
@@ -1755,7 +1772,16 @@ multi MAIN('test') {
1755 1772
             Adventure::PlayerTook.new(
1756 1773
                 :thing<rope>,
1757 1774
             ),
1758  
-            'taking the rope from the car';
  1775
+            'taking the rope from the car (+)';
  1776
+    }
  1777
+
  1778
+    {
  1779
+        my $game = Crypt::Game.new();
  1780
+
  1781
+        throws_exception
  1782
+            { $game.take('flashlight') },
  1783
+            X::Adventure::NoSuchThingHere,
  1784
+            'taking the flashlight from the car (-) car not open';
1759 1785
     }
1760 1786
 
1761 1787
     done;

0 notes on commit a309abb

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