Fix: turn value sometimes cleared or incorect.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Sat, 20 Sep 2014 01:16:14 +0300
changeset 97 b3cadad6ef14
parent 96 a9a6e08c9e35
child 98 eb4f89e2a001
Fix: turn value sometimes cleared or incorect.
2048.html
--- a/2048.html	Sat Sep 20 01:01:53 2014 +0300
+++ b/2048.html	Sat Sep 20 01:16:14 2014 +0300
@@ -428,9 +428,8 @@
       maxDom.innerHTML = '' + ui.board.val2048(score.max);
       turnDom.innerHTML = '' + turn;
     }
-    ui.score.speed = function(speed, turn) {
+    ui.score.speed = function(speed) {
       speedDom.innerHTML = '' + speed;
-      turnDom.innerHTML = '' + turn;
     }
 
     ////////////////////////////////////////////////////////////////
@@ -607,15 +606,17 @@
         if (updated) {
           board.putRandom(ui.board.position);
         } else {
-          ui.game.finishStep();
+          ui.board.turn += step;
+          ui.game.refresh();
           ui.game.setMessage("Wrong move!");
           return;
         }
         step++; 
       }
       var tsTo = new Date().getTime();
+      ui.board.turn += step;
       ui.game.finishStep();
-      ui.score.speed(parseFloat((step*1000.0/(tsTo-tsFrom)).toPrecision(3)), step);
+      ui.score.speed(parseFloat((step*1000.0/(tsTo-tsFrom)).toPrecision(3)));
       ui.game.setMessage("Game over!");
       ui.ai.current.cleanup();
     }
@@ -668,8 +669,9 @@
         step++; 
       }
       var tsTo = new Date().getTime();
+      ui.board.turn += step;
       ui.game.refresh();
-      ui.score.speed(parseFloat((step*1000.0/(tsTo-tsFrom)).toPrecision(3)), step);
+      ui.score.speed(parseFloat((step*1000.0/(tsTo-tsFrom)).toPrecision(3)));
       ui.ai.current.cleanup();
     }
     document.getElementById("until").addEventListener("click", ui.action.until, false);