Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bin/crypt] de-special-cased crypt wrapper methods

...and put the special hanoi-handling logic in hooks instead.
  • Loading branch information...
commit 4a89e8f3f057ca8be7d9e448abc9968be991b839 1 parent 8712743
Carl Mäsak authored July 31, 2012

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

  1. 46  bin/crypt
46  bin/crypt
@@ -1290,11 +1290,26 @@ class Crypt::Game {
1290 1290
             for <left middle right> X~ ' rod' -> $rod {
1291 1291
                 .place_thing: $rod, 'contents:hanoi';
1292 1292
                 .make_thing_a_platform: $rod;
  1293
+                .on_put: $rod,
  1294
+                    -> $_ {
  1295
+                        when 'tiny disk' {
  1296
+                            my @events = $!hanoi.add: $_, $rod.words[0];
  1297
+                            for @events {
  1298
+                                when Hanoi::AchievementUnlocked {
  1299
+                                    push @events,
  1300
+                                        $!engine.remark('floor-reveals-hole'),
  1301
+                                        $!engine.connect(<hall cave>, 'down');
  1302
+                                }
  1303
+                            }
  1304
+                            @events;
  1305
+                        }
  1306
+                    };
1293 1307
             }
1294 1308
             for <tiny small medium large huge> X~ ' disk' -> $disk {
1295 1309
                 .place_thing: $disk, 'contents:left rod';
1296 1310
             }
1297 1311
             .make_thing_carryable: 'tiny disk';
  1312
+            .on_take: 'tiny disk', { $!hanoi.remove: 'tiny disk' };
1298 1313
 
1299 1314
             # Things in cave
1300 1315
             .place_thing: 'fire', 'cave';
@@ -1373,11 +1388,7 @@ class Crypt::Game {
1373 1388
     }
1374 1389
 
1375 1390
     method take($thing) {
1376  
-        my @events = $!engine.take($thing);
1377  
-        if $thing eq 'tiny disk' && $!player_location eq 'hall' {
1378  
-            @events.unshift: $!hanoi.remove: $thing;
1379  
-        }
1380  
-        return @events;
  1391
+        return $!engine.take($thing);
1381 1392
     }
1382 1393
 
1383 1394
     method drop($thing) {
@@ -1389,18 +1400,7 @@ class Crypt::Game {
1389 1400
     }
1390 1401
 
1391 1402
     method put_thing_on($thing, $on) {
1392  
-        my @events = $!engine.put_thing_on($thing, $on);
1393  
-        if $thing eq 'tiny disk' && $on ~~ /^ (\w+) ' rod' $/ {
1394  
-            @events.push: $!hanoi.add: $thing, ~$0;
1395  
-            for @events {
1396  
-                when Hanoi::AchievementUnlocked {
1397  
-                    push @events,
1398  
-                        $!engine.remark('floor-reveals-hole'),
1399  
-                        $!engine.connect(<hall cave>, 'down');
1400  
-                }
1401  
-            }
1402  
-        }
1403  
-        return @events;
  1403
+        return $!engine.put_thing_on($thing, $on);
1404 1404
     }
1405 1405
 
1406 1406
     method read($thing) {
@@ -3061,13 +3061,13 @@ multi MAIN('test') {
3061 3061
         $game.use('flashlight');
3062 3062
         is $game.take('tiny disk'),
3063 3063
             [
  3064
+                Adventure::PlayerTook.new(
  3065
+                    :thing('tiny disk'),
  3066
+                ),
3064 3067
                 Hanoi::DiskRemoved.new(
3065 3068
                     :disk('tiny disk'),
3066 3069
                     :source<left>,
3067 3070
                 ),
3068  
-                Adventure::PlayerTook.new(
3069  
-                    :thing('tiny disk'),
3070  
-                ),
3071 3071
             ],
3072 3072
             'can take the tiny disk from the hanoi game';
3073 3073
     }
@@ -3182,13 +3182,13 @@ multi MAIN('test') {
3182 3182
         $game.put_thing_on('tiny disk', 'right rod');
3183 3183
         is $game.take('tiny disk'),
3184 3184
             [
  3185
+                Adventure::PlayerTook.new(
  3186
+                    :thing('tiny disk'),
  3187
+                ),
3185 3188
                 Hanoi::DiskRemoved.new(
3186 3189
                     :disk<tiny disk>,
3187 3190
                     :source<right>,
3188 3191
                 ),
3189  
-                Adventure::PlayerTook.new(
3190  
-                    :thing('tiny disk'),
3191  
-                ),
3192 3192
             ],
3193 3193
             'can take the tiny disk, put it back, and take it again';
3194 3194
     }

0 notes on commit 4a89e8f

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