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 put things on non-platforms

  • Loading branch information...
commit 6d2119f9f9d0678f78b0bc28f2406c6ce642bd80 1 parent f125f79
Carl Mäsak authored July 12, 2012

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

  1. 41  bin/crypt
41  bin/crypt
@@ -279,6 +279,10 @@ class Adventure::PlayerPutOn does Event {
279 279
     has $.on;
280 280
 }
281 281
 
  282
+class Adventure::ThingMadeAPlatform does Event {
  283
+    has $.thing;
  284
+}
  285
+
282 286
 class X::Adventure is Exception {
283 287
 }
284 288
 
@@ -344,6 +348,14 @@ class X::Adventure::YoDawg is X::Adventure {
344 348
     }
345 349
 }
346 350
 
  351
+class X::Adventure::CannotPutOnNonPlatform is X::Adventure {
  352
+    has $.on;
  353
+
  354
+    method message {
  355
+        "You cannot put things on the $.on"
  356
+    }
  357
+}
  358
+
347 359
 class Adventure::Engine {
348 360
     my @possible_directions = <
349 361
         north south east west
@@ -361,6 +373,7 @@ class Adventure::Engine {
361 373
     has %!openable_things;
362 374
     has %!open_things;
363 375
     has %!containers;
  376
+    has %!platforms;
364 377
 
365 378
     method connect(@rooms, $direction) {
366 379
         die X::Adventure::NoSuchDirection.new(:action('connect rooms'), :$direction)
@@ -489,9 +502,15 @@ class Adventure::Engine {
489 502
     }
490 503
 
491 504
     method make_thing_a_platform($thing) {
  505
+        my @events = Adventure::ThingMadeAPlatform.new(:$thing);
  506
+        self!apply($_) for @events;
  507
+        @events;
492 508
     }
493 509
 
494 510
     method put_thing_on($thing, $on) {
  511
+        die X::Adventure::CannotPutOnNonPlatform.new(:$on)
  512
+            unless %!platforms{$on};
  513
+
495 514
         Adventure::PlayerPutOn.new(:$thing, :$on);
496 515
     }
497 516
 
@@ -555,6 +574,9 @@ class Adventure::Engine {
555 574
         when Adventure::ThingMadeAContainer {
556 575
             %!containers{.thing} = True;
557 576
         }
  577
+        when Adventure::ThingMadeAPlatform {
  578
+            %!platforms{.thing} = True;
  579
+        }
558 580
     }
559 581
 }
560 582
 
@@ -1145,6 +1167,25 @@ multi MAIN('test') {
1145 1167
             'putting a thing on another (+)';
1146 1168
     }
1147 1169
 
  1170
+    {
  1171
+        my $engine = Adventure::Engine.new();
  1172
+
  1173
+        $engine.place_thing('hole', 'street');
  1174
+        $engine.place_thing('doll', 'street');
  1175
+        # don't make hole a platform
  1176
+        $engine.place_player('street');
  1177
+        throws_exception
  1178
+            { $engine.put_thing_on('doll', 'hole') },
  1179
+            X::Adventure::CannotPutOnNonPlatform,
  1180
+            'putting a thing on another (-) it is not a platform',
  1181
+            {
  1182
+                is .on, 'hole', '.on attribute';
  1183
+                is .message,
  1184
+                    "You cannot put things on the hole",
  1185
+                    '.message attribute';
  1186
+            };
  1187
+    }
  1188
+
1148 1189
     done;
1149 1190
 }
1150 1191
 

0 notes on commit 6d2119f

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