Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] looking inside the car works

  • Loading branch information...
commit ae59ad95036c014d42b1539d0283eb1d18356b46 1 parent d570802
Carl Mäsak authored July 17, 2012

Showing 1 changed file with 27 additions and 5 deletions. Show diff stats Hide diff stats

  1. 32  bin/crypt
32  bin/crypt
@@ -464,16 +464,25 @@ class Adventure::Engine {
464 464
         self!apply_and_return: @events;
465 465
     }
466 466
 
  467
+    method !contents_of($thing) {
  468
+        return %!thing_rooms.grep({.value eq "contents:$thing"})>>.key;
  469
+    }
  470
+
467 471
     method !explicit_things_at($location) {
468  
-        return unless $!player_location;
469 472
         sub is_here_and_explicit($_) {
470 473
             %!thing_rooms{$_} eq $location && !%!implicit_things{$_}
471 474
         }
472  
-        return %!thing_rooms.keys.grep(&is_here_and_explicit);
473  
-    }
474 475
 
475  
-    method !contents_of($thing) {
476  
-        return %!thing_rooms.grep({.value eq "contents:$thing"})>>.key;
  476
+        return unless $!player_location;
  477
+        return gather for %!thing_rooms.keys -> $thing {
  478
+            next unless is_here_and_explicit($thing);
  479
+            if %!open_things{$thing} && self!contents_of($thing) {
  480
+                take $thing => self!explicit_things_at("contents:$thing");
  481
+            }
  482
+            else {
  483
+                take $thing;
  484
+            }
  485
+        }
477 486
     }
478 487
 
479 488
     method walk($direction) {
@@ -1705,6 +1714,19 @@ multi MAIN('test') {
1705 1714
             'opening the car';
1706 1715
     }
1707 1716
 
  1717
+    {
  1718
+        my $game = Crypt::Game.new();
  1719
+
  1720
+        $game.open('car');
  1721
+        is $game.look(),
  1722
+            Adventure::PlayerLooked.new(
  1723
+                :room<clearing>,
  1724
+                :exits<east>,
  1725
+                :things(car => <flashlight rope>),
  1726
+            ),
  1727
+            'looking inside the car';
  1728
+    }
  1729
+
1708 1730
     done;
1709 1731
 }
1710 1732
 

0 notes on commit ae59ad9

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