Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] putting things in themselves

Not allowed.
  • Loading branch information...
commit 71900d3fe6283d37abdd63661840fcc8578bb9a0 1 parent 38a7ce0
Carl Mäsak authored July 12, 2012

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

  1. 29  bin/crypt
29  bin/crypt
@@ -331,6 +331,14 @@ class X::Adventure::CannotPutInNonContainer is X::Adventure {
331 331
     }
332 332
 }
333 333
 
  334
+class X::Adventure::YoDawg is X::Adventure {
  335
+    has $.in;
  336
+
  337
+    method message {
  338
+        "Yo dawg, I know you like a $.in so I put a $.in in your $.in"
  339
+    }
  340
+}
  341
+
334 342
 class Adventure::Engine {
335 343
     my @possible_directions = <
336 344
         north south east west
@@ -462,6 +470,9 @@ class Adventure::Engine {
462 470
         die X::Adventure::CannotPutInNonContainer.new(:$in)
463 471
             unless %!containers{$in};
464 472
 
  473
+        die X::Adventure::YoDawg.new(:$in)
  474
+            if $thing eq $in;
  475
+
465 476
         my @events;
466 477
 
467 478
         if %!openable_things{$in} && !%!open_things{$in} {
@@ -1089,6 +1100,24 @@ multi MAIN('test') {
1089 1100
             'putting a thing inside another (+) container was closed';
1090 1101
     }
1091 1102
 
  1103
+    {
  1104
+        my $engine = Adventure::Engine.new();
  1105
+
  1106
+        $engine.place_thing('box', 'street');
  1107
+        $engine.make_thing_a_container('box');
  1108
+        $engine.place_player('street');
  1109
+        throws_exception
  1110
+            { $engine.put_thing_in('box', 'box') },
  1111
+            X::Adventure::YoDawg,
  1112
+            'putting a thing inside another (-) but it is the same thing',
  1113
+            {
  1114
+                is .in, 'box', '.in attribute';
  1115
+                is .message,
  1116
+                    "Yo dawg, I know you like a box so I put a box in your box",
  1117
+                    '.message attribute';
  1118
+            };
  1119
+    }
  1120
+
1092 1121
     done;
1093 1122
 }
1094 1123
 

0 notes on commit 71900d3

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