Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] implement 'inventory' command

  • Loading branch information...
commit 8d2d80880bc73bf110accc9cebccf89bed20d74f 1 parent b8f270b
Carl Mäsak authored July 28, 2012

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

  1. 50  bin/crypt
50  bin/crypt
@@ -354,6 +354,10 @@ class Adventure::LightSourceSwitchedOn does Event {
354 354
 class Adventure::GameFinished does Event {
355 355
 }
356 356
 
  357
+class Adventure::PlayerCheckedInventory does Event {
  358
+    has @.things;
  359
+}
  360
+
357 361
 class X::Adventure is Exception {
358 362
 }
359 363
 
@@ -705,6 +709,24 @@ class Adventure::Engine {
705 709
         self!apply_and_return: @events;
706 710
     }
707 711
 
  712
+    method inventory() {
  713
+        die X::Adventure::GameOver.new()
  714
+            if $!game_finished;
  715
+
  716
+        die X::Adventure::PlayerNowhere.new()
  717
+            unless defined $!player_location;
  718
+
  719
+        my $thing = 'player inventory';
  720
+        my @events = Adventure::PlayerCheckedInventory.new(
  721
+            :things(self!explicit_things_at('player inventory'))
  722
+        );
  723
+        if %!examine_hooks{$thing} -> &hook {
  724
+            @events.push(&hook());
  725
+        }
  726
+
  727
+        self!apply_and_return: @events;
  728
+    }
  729
+
708 730
     method make_thing_openable($thing) {
709 731
         %!openable_things{$thing} = True;
710 732
     }
@@ -1309,6 +1331,10 @@ class Crypt::Game {
1309 1331
         return $!engine.examine($thing);
1310 1332
     }
1311 1333
 
  1334
+    method inventory() {
  1335
+        return $!engine.inventory();
  1336
+    }
  1337
+
1312 1338
     method take($thing) {
1313 1339
         my @events;
1314 1340
         if $thing eq 'tiny disk' {
@@ -1444,7 +1470,8 @@ look                         | take banana
1444 1470
 examine banana               | drop banana
1445 1471
 [walk] north/south/east/west | put banana in bag
1446 1472
        (or just n/s/e/w)     | place banana on throne
1447  
-open bag                     | close bag";
  1473
+open bag                     | close bag
  1474
+inventory";
1448 1475
             }
1449 1476
 
1450 1477
             when 'save' {
@@ -1587,6 +1614,27 @@ open bag                     | close bag";
1587 1614
                         say "You put the {.disk} on the {.target} rod.";
1588 1615
                         print_hanoi_game(@all_events);
1589 1616
                     }
  1617
+                    when Adventure::PlayerCheckedInventory {
  1618
+                        if .things {
  1619
+                            say "You are carrying:";
  1620
+                            for .things -> $thing {
  1621
+                                if $thing ~~ Pair {
  1622
+                                    say "A $thing.key().";
  1623
+                                    # XXX: Needs to work for nested calls, too
  1624
+                                    say "The $thing.key() contains:";
  1625
+                                    for $thing.value.list -> $containee {
  1626
+                                        say "  A $containee.";
  1627
+                                    }
  1628
+                                }
  1629
+                                else {
  1630
+                                    say "A $thing.";
  1631
+                                }
  1632
+                            }
  1633
+                        }
  1634
+                        else {
  1635
+                            say "You are empty-handed.";
  1636
+                        }
  1637
+                    }
1590 1638
                 }
1591 1639
                 CATCH {
1592 1640
                     when X::Adventure { say .message, '.' }

0 notes on commit 8d2d808

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