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 read non-readable things

  • Loading branch information...
commit 9dc36152ae8556842cb36174dd15753cdfa5fda0 1 parent e6f9ee6
Carl Mäsak authored July 13, 2012

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

  1. 40  bin/crypt
40  bin/crypt
@@ -287,6 +287,10 @@ class Adventure::PlayerRead does Event {
287 287
     has $.thing;
288 288
 }
289 289
 
  290
+class Adventure::ThingMadeReadable does Event {
  291
+    has $.thing;
  292
+}
  293
+
290 294
 class X::Adventure is Exception {
291 295
 }
292 296
 
@@ -361,6 +365,14 @@ class X::Adventure::CannotPutOnNonPlatform is X::Adventure {
361 365
     }
362 366
 }
363 367
 
  368
+class X::Adventure::ThingIsNotReadable is X::Adventure {
  369
+    has $.thing;
  370
+
  371
+    method message {
  372
+        "There is nothing to read on the $.thing"
  373
+    }
  374
+}
  375
+
364 376
 class Adventure::Engine {
365 377
     my @possible_directions = <
366 378
         north south east west
@@ -379,6 +391,7 @@ class Adventure::Engine {
379 391
     has %!open_things;
380 392
     has %!containers;
381 393
     has %!platforms;
  394
+    has %!readable_things;
382 395
 
383 396
     method connect(@rooms, $direction) {
384 397
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -523,9 +536,15 @@ class Adventure::Engine {
523 536
     }
524 537
 
525 538
     method make_thing_readable($thing) {
  539
+        my @events = Adventure::ThingMadeReadable.new(:$thing);
  540
+        self!apply($_) for @events;
  541
+        @events;
526 542
     }
527 543
 
528 544
     method read($thing) {
  545
+        die X::Adventure::ThingIsNotReadable.new(:$thing)
  546
+            unless %!readable_things{$thing};
  547
+
529 548
         Adventure::PlayerRead.new(:$thing);
530 549
     }
531 550
 
@@ -592,6 +611,9 @@ class Adventure::Engine {
592 611
         when Adventure::ThingMadeAPlatform {
593 612
             %!platforms{.thing} = True;
594 613
         }
  614
+        when Adventure::ThingMadeReadable {
  615
+            %!readable_things{.thing} = True;
  616
+        }
595 617
     }
596 618
 }
597 619
 
@@ -1234,6 +1256,24 @@ multi MAIN('test') {
1234 1256
             'reading a thing (+)';
1235 1257
     }
1236 1258
 
  1259
+    {
  1260
+        my $engine = Adventure::Engine.new();
  1261
+
  1262
+        $engine.place_thing('ball', 'library');
  1263
+        # don't make ball readable
  1264
+        $engine.place_player('library');
  1265
+        throws_exception
  1266
+            { $engine.read('ball') },
  1267
+            X::Adventure::ThingIsNotReadable,
  1268
+            'reading a thing (-) it is not readable',
  1269
+            {
  1270
+                is .thing, 'ball', '.thing attribute';
  1271
+                is .message,
  1272
+                    "There is nothing to read on the ball",
  1273
+                    '.message attribute';
  1274
+            };
  1275
+    }
  1276
+
1237 1277
     done;
1238 1278
 }
1239 1279
 

0 notes on commit 9dc3615

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