Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] a flashlight and a rope in the car

And they're revealed when we open the car.
  • Loading branch information...
commit d570802f689a8609df2d4c9ba53a26dbad236db6 1 parent fd3ee8c
Carl Mäsak authored July 17, 2012

Showing 1 changed file with 37 additions and 1 deletion. Show diff stats Hide diff stats

  1. 38  bin/crypt
38  bin/crypt
@@ -320,6 +320,11 @@ class Adventure::ThingMadeImplicit does Event {
320 320
     has $.thing;
321 321
 }
322 322
 
  323
+class Adventure::ContentsRevealed does Event {
  324
+    has $.container;
  325
+    has @.contents;
  326
+}
  327
+
323 328
 class X::Adventure is Exception {
324 329
 }
325 330
 
@@ -467,6 +472,10 @@ class Adventure::Engine {
467 472
         return %!thing_rooms.keys.grep(&is_here_and_explicit);
468 473
     }
469 474
 
  475
+    method !contents_of($thing) {
  476
+        return %!thing_rooms.grep({.value eq "contents:$thing"})>>.key;
  477
+    }
  478
+
470 479
     method walk($direction) {
471 480
         die X::Adventure::PlayerNowhere.new()
472 481
             unless defined $!player_location;
@@ -576,6 +585,14 @@ class Adventure::Engine {
576 585
             if %!open_things{$thing};
577 586
 
578 587
         my @events = Adventure::PlayerOpened.new(:$thing);
  588
+        my @contents = self!contents_of($thing);
  589
+        if @contents {
  590
+            @events.push(
  591
+                Adventure::ContentsRevealed.new(
  592
+                    :container($thing), :@contents
  593
+                )
  594
+            );
  595
+        }
579 596
         self!apply_and_return: @events;
580 597
     }
581 598
 
@@ -795,7 +812,7 @@ class Adventure::Engine {
795 812
 }
796 813
 
797 814
 class Crypt::Game {
798  
-    has $!engine handles <walk save>;
  815
+    has $!engine handles <walk save open>;
799 816
 
800 817
     submethod BUILD() {
801 818
         $!engine = Adventure::Engine.new();
@@ -812,6 +829,9 @@ class Crypt::Game {
812 829
                 False;
813 830
             });
814 831
             .place_thing('car', 'clearing');
  832
+            .place_thing('flashlight', 'contents:car');
  833
+            .place_thing('rope', 'contents:car');
  834
+            .make_thing_openable('car');
815 835
             .place_player('clearing');
816 836
         }
817 837
     }
@@ -1669,6 +1689,22 @@ multi MAIN('test') {
1669 1689
             'looking at the room, implicit thing';
1670 1690
     }
1671 1691
 
  1692
+    {
  1693
+        my $game = Crypt::Game.new();
  1694
+
  1695
+        is $game.open('car'),
  1696
+            [
  1697
+                Adventure::PlayerOpened.new(
  1698
+                    :thing<car>,
  1699
+                ),
  1700
+                Adventure::ContentsRevealed.new(
  1701
+                    :container<car>,
  1702
+                    :contents<flashlight rope>,
  1703
+                ),
  1704
+            ],
  1705
+            'opening the car';
  1706
+    }
  1707
+
1672 1708
     done;
1673 1709
 }
1674 1710
 

0 notes on commit d570802

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