Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[crypt.pl] post-unlocking achievement logic

  • Loading branch information...
commit 6aa70d45d0ce1a8ecb6361894e72597db3539bca 1 parent b9caade
Carl Mäsak authored July 01, 2012

Showing 1 changed file with 9 additions and 1 deletion. Show diff stats Hide diff stats

  1. 10  crypt.pl
10  crypt.pl
@@ -55,6 +55,8 @@
55 55
         right  => [],
56 56
     ;
57 57
 
  58
+    has $!achievement = 'locked';
  59
+
58 60
     method move($source, $target) {
59 61
         die X::Hanoi::NoSuchRod.new(:rod<source>, :name($source))
60 62
             unless %!state.exists($source);
@@ -77,7 +79,8 @@
77 79
         @target_rod.push( @source_rod.pop );
78 80
         my $size = $moved_disk.words[0];
79 81
         my @events = DiskMoved.new(:$size, :$source, :$target);
80  
-        if %!state<right> == @disks {
  82
+        if %!state<right> == @disks && $!achievement eq 'locked' {
  83
+            $!achievement = 'unlocked';
81 84
             @events.push(AchievementUnlocked.new);
82 85
         }
83 86
         return @events;
@@ -197,6 +200,11 @@ (&code, $ex_type, &followup?)
197 200
                 DiskMoved.new(:size<tiny>, :$source, :$target),
198 201
                 AchievementUnlocked.new(),
199 202
             ), 'putting all disks on the right rod unlocks achievement';
  203
+
  204
+            $game.move($target, $source);
  205
+            is $game.move($source, $target), (
  206
+                DiskMoved.new(:size<tiny>, :$source, :$target),
  207
+            ), 'moving things back and forth does not unlock achievement again';
200 208
         }
201 209
     }
202 210
 

0 notes on commit 6aa70d4

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