Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] you can put leaves in the basket

  • Loading branch information...
commit 5fcb6488f78e72309f99bc972cd00886533471b1 1 parent 88c1694
Carl Mäsak authored July 20, 2012
61  bin/crypt
@@ -504,6 +504,11 @@ class Adventure::Engine {
504 504
         return False;
505 505
     }
506 506
 
  507
+    method !thing_in_room_or_inventory($thing) {
  508
+        self!is_thing_in($thing, $!player_location)
  509
+        || self!is_thing_in($thing, 'player inventory');
  510
+    }
  511
+
507 512
     method walk($direction) {
508 513
         die X::Adventure::PlayerNowhere.new()
509 514
             unless defined $!player_location;
@@ -636,8 +641,11 @@ class Adventure::Engine {
636 641
         die X::Adventure::PlayerNowhere.new()
637 642
             unless defined $!player_location;
638 643
 
639  
-        # XXX: should check if the first thing is there
640  
-        # XXX: should check if the second thing is there
  644
+        die X::Adventure::NoSuchThingHere.new(:$thing)
  645
+            unless self!thing_in_room_or_inventory($thing);
  646
+
  647
+        die X::Adventure::NoSuchThingHere.new(:thing($in))
  648
+            unless self!thing_in_room_or_inventory($in);
641 649
 
642 650
         die X::Adventure::ThingNotCarryable.new(:action<put>, :$thing)
643 651
             unless %!carryable_things{$thing};
@@ -876,7 +884,7 @@ class Crypt::Game {
876 884
             .alias_direction('chamber', 'out', 'north');
877 885
             .connect(<chamber hall>, 'south');
878 886
             .alias_direction('chamber', 'in', 'south');
879  
-            .alias_direction('cave', 'out', 'north');
  887
+            .alias_direction('hall', 'out', 'north');
880 888
             .connect(<hall cave>, 'down');
881 889
             .connect(<cave crypt>, 'northwest');
882 890
             .on_try_exit('cave', 'northwest', {
@@ -896,8 +904,7 @@ class Crypt::Game {
896 904
                 'car',
897 905
                 -> $_ {
898 906
                     when 'leaves' { $!engine.remark('car-full-of-leaves') }
899  
-                }
900  
-            );
  907
+                });
901 908
 
902 909
             # Things on hill
903 910
             .place_thing('grass', 'hill');
@@ -916,6 +923,18 @@ class Crypt::Game {
916 923
             .make_thing_implicit('leaves');
917 924
             .make_thing_carryable('leaves');
918 925
 
  926
+            # Things in chamber
  927
+            .place_thing('basket', 'chamber');
  928
+            .make_thing_a_container('basket');
  929
+            .on_put(
  930
+                'basket',
  931
+                -> $_ {
  932
+                    when 'leaves' {
  933
+                        $!engine.connect(<chamber hall>, 'south'),
  934
+                        $!engine.remark('passageway-opens-up');
  935
+                    }
  936
+                });
  937
+
919 938
             .place_player('clearing');
920 939
         }
921 940
     }
@@ -1973,6 +1992,7 @@ multi MAIN('test') {
1973 1992
                 Adventure::PlayerLooked.new(
1974 1993
                     :room<chamber>,
1975 1994
                     :exits<south north>,
  1995
+                    :things<basket>,
1976 1996
                 ),
1977 1997
             ],
1978 1998
             'walking into the hill (+) after opening the door';
@@ -2011,6 +2031,37 @@ multi MAIN('test') {
2011 2031
             'putting the leaves in the car';
2012 2032
     }
2013 2033
 
  2034
+    sub game_from_chamber {
  2035
+        my $game = Crypt::Game.new();
  2036
+
  2037
+        $game.walk('east');
  2038
+        $game.take('leaves');
  2039
+        $game.examine('bushes');
  2040
+        $game.open('door');
  2041
+        $game.walk('in');
  2042
+        return $game;
  2043
+    }
  2044
+
  2045
+    {
  2046
+        my $game = game_from_chamber();
  2047
+
  2048
+        is $game.put_thing_in('leaves', 'basket'),
  2049
+            [
  2050
+                Adventure::PlayerPutIn.new(
  2051
+                    :thing<leaves>,
  2052
+                    :in<basket>,
  2053
+                ),
  2054
+                Adventure::TwoRoomsConnected.new(
  2055
+                    :rooms<chamber hall>,
  2056
+                    :direction<south>,
  2057
+                ),
  2058
+                Adventure::GameRemarked.new(
  2059
+                    :remark<passageway-opens-up>,
  2060
+                ),
  2061
+            ],
  2062
+            'putting the leaves in the basket';
  2063
+    }
  2064
+
2014 2065
     done;
2015 2066
 }
2016 2067
 
4  game-data/descriptions
@@ -55,3 +55,7 @@ They look like the kind of leaves that would love a good rustle.
55 55
 
56 56
 == remark:car-full-of-leaves
57 57
 Great. Now your car is full of leaves.
  58
+
  59
+== remark:passageway-opens-up
  60
+The ground rumbles and shakes a bit.
  61
+A passageway opens up to the south, into the caverns.

0 notes on commit 5fcb648

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