Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[crypt.pl] adding a disk

  • Loading branch information...
commit 89ce1449010437126f1dea47b90a5c88420df0bf 1 parent 00629f1
Carl Mäsak authored July 01, 2012

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

  1. 16  crypt.pl
16  crypt.pl
@@ -27,6 +27,11 @@
27 27
     has $.source;
28 28
 }
29 29
 
  30
+class Hanoi::DiskAdded does Event {
  31
+    has $.size;
  32
+    has $.target;
  33
+}
  34
+
30 35
 class X::Hanoi::LargerOnSmaller is Exception {
31 36
     has $.larger;
32 37
     has $.smaller;
@@ -143,6 +148,13 @@
143 148
         return @events;
144 149
     }
145 150
 
  151
+    method add($disk, $target) {
  152
+        my $size = $disk.words[0];
  153
+        my @events = Hanoi::DiskAdded.new(:$size, :$target);
  154
+        self!apply($_) for @events;
  155
+        return @events;
  156
+    }
  157
+
146 158
     # The method will throw X::Hanoi::CoveredDisk if the disk is not topmost,
147 159
     # or X::Hanoi::DiskHasBeenRemoved if the disk isn't found on any rod.
148 160
     method !rod_with_disk($disk, $action) {
@@ -417,6 +429,10 @@ (&code, $ex_type, $message, &followup?)
417 429
                     'Cannot move the tiny disk because it has been removed',
418 430
                     '.message attribute';
419 431
             };
  432
+
  433
+        is $game.add('tiny disk', 'left'),
  434
+           Hanoi::DiskAdded.new(:size<tiny>, :target<left>),
  435
+           'adding a disk (+)';
420 436
     }
421 437
 
422 438
     done;

0 notes on commit 89ce144

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