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 open not openable things

  • Loading branch information...
commit e0ac8d7cd40d94b7d3f73032e6e4181e3e0e5ee9 1 parent 97260bd
Carl Mäsak authored

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

  1. 28  bin/crypt
28  bin/crypt
@@ -298,6 +298,14 @@ class X::Adventure::NoSuchThingHere is X::Adventure {
298 298
     }
299 299
 }
300 300
 
  301
+class X::Adventure::ThingNotOpenable is X::Adventure {
  302
+    has $.thing;
  303
+
  304
+    method message {
  305
+        "You cannot open the $.thing"
  306
+    }
  307
+}
  308
+
301 309
 class Adventure::Engine {
302 310
     my @possible_directions = <
303 311
         north south east west
@@ -312,6 +320,7 @@ class Adventure::Engine {
312 320
     has %!seen_room;
313 321
     has %!try_exit_hooks;
314 322
     has %!thing_rooms;
  323
+    has %!openable_things;
315 324
 
316 325
     method connect(@rooms, $direction) {
317 326
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -401,9 +410,13 @@ class Adventure::Engine {
401 410
     }
402 411
 
403 412
     method make_thing_openable($thing) {
  413
+        %!openable_things{$thing} = True;
404 414
     }
405 415
 
406 416
     method open($thing) {
  417
+        die X::Adventure::ThingNotOpenable.new(:$thing)
  418
+            unless %!openable_things{$thing};
  419
+
407 420
         Adventure::PlayerOpened.new(:$thing);
408 421
     }
409 422
 
@@ -931,6 +944,21 @@ multi MAIN('test') {
931 944
             'opening an object (+)';
932 945
     }
933 946
 
  947
+    {
  948
+        my $engine = Adventure::Engine.new();
  949
+
  950
+        $engine.place_thing('ball', 'street');
  951
+        $engine.place_player('street');
  952
+        throws_exception
  953
+            { $engine.open('ball') },
  954
+            X::Adventure::ThingNotOpenable,
  955
+            'opening an object (-) it is not openable',
  956
+            {
  957
+                is .thing, 'ball', '.thing attribute';
  958
+                is .message, "You cannot open the ball", '.message attribute';
  959
+            };
  960
+    }
  961
+
934 962
     done;
935 963
 }
936 964
 

0 notes on commit e0ac8d7

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