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 non-carryable things

  • Loading branch information...
commit 9a88a7ff57537a5cd1fa89c3ba26e9ed67af1611 1 parent c632483
Carl Mäsak authored July 15, 2012

Showing 1 changed file with 41 additions and 0 deletions. Show diff stats Hide diff stats

  1. 41  bin/crypt
41  bin/crypt
@@ -305,6 +305,10 @@ class Adventure::PlayerTook does Event {
305 305
     has $.thing;
306 306
 }
307 307
 
  308
+class Adventure::ThingMadeCarryable does Event {
  309
+    has $.thing;
  310
+}
  311
+
308 312
 class X::Adventure is Exception {
309 313
 }
310 314
 
@@ -387,6 +391,15 @@ class X::Adventure::ThingNotReadable is X::Adventure {
387 391
     }
388 392
 }
389 393
 
  394
+class X::Adventure::ThingNotCarryable is X::Adventure {
  395
+    has $.action;
  396
+    has $.thing;
  397
+
  398
+    method message {
  399
+        "You cannot $.action the $.thing"
  400
+    }
  401
+}
  402
+
390 403
 class Adventure::Engine {
391 404
     my @possible_directions = <
392 405
         north south east west
@@ -408,6 +421,7 @@ class Adventure::Engine {
408 421
     has %!readable_things;
409 422
     has %!hidden_things;
410 423
     has %!examine_hooks;
  424
+    has %!carryable_things;
411 425
 
412 426
     method connect(@rooms, $direction) {
413 427
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -608,9 +622,15 @@ class Adventure::Engine {
608 622
     }
609 623
 
610 624
     method make_thing_carryable($thing) {
  625
+        my @events = Adventure::ThingMadeCarryable.new(:$thing);
  626
+        self!apply($_) for @events;
  627
+        @events;
611 628
     }
612 629
 
613 630
     method take($thing) {
  631
+        die X::Adventure::ThingNotCarryable.new(:action<take>, :$thing)
  632
+            unless %!carryable_things{$thing};
  633
+
614 634
         my @events = Adventure::PlayerTook.new(:$thing);
615 635
         self!apply($_) for @events;
616 636
         @events;
@@ -692,6 +712,9 @@ class Adventure::Engine {
692 712
         when Adventure::ThingUnhidden {
693 713
             %!hidden_things{.thing} = False;
694 714
         }
  715
+        when Adventure::ThingMadeCarryable {
  716
+            %!carryable_things{.thing} = True;
  717
+        }
695 718
     }
696 719
 }
697 720
 
@@ -1415,6 +1438,24 @@ multi MAIN('test') {
1415 1438
             'taking a thing (+)';
1416 1439
     }
1417 1440
 
  1441
+    {
  1442
+        my $engine = Adventure::Engine.new();
  1443
+
  1444
+        $engine.place_thing('table', 'saloon');
  1445
+        # don't make table carryable
  1446
+        throws_exception
  1447
+            { $engine.take('table') },
  1448
+            X::Adventure::ThingNotCarryable,
  1449
+            'taking a thing (-) it is not carryable',
  1450
+            {
  1451
+                is .action, 'take', '.action attribute';
  1452
+                is .thing, 'table', '.thing attribute';
  1453
+                is .message,
  1454
+                    "You cannot take the table",
  1455
+                    '.message attribute';
  1456
+            };
  1457
+    }
  1458
+
1418 1459
     done;
1419 1460
 }
1420 1461
 

0 notes on commit 9a88a7f

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