2048.html
changeset 46 4dadaff6eba4
parent 45 0bcdec3bdaa8
child 52 e4e21d2fcbe7
--- a/2048.html	Thu Sep 11 01:47:54 2014 +0300
+++ b/2048.html	Thu Sep 11 02:16:57 2014 +0300
@@ -329,10 +329,11 @@
       speedDom.innerHTML = '0';
       turnDom.innerHTML = '0';
     }
-    ui.score.update = function(brd) {
+    ui.score.update = function(brd, turn) {
       var score = board.score(brd);
       scoreDom.innerHTML = '' + score.score;
-      maxDom.innerHTML = '' + score.max;
+      maxDom.innerHTML = '' + ui.board.val2048(score.max);
+      turnDom.innerHTML = '' + turn;
     }
     ui.score.speed = function(speed, turn) {
       speedDom.innerHTML = '' + speed;
@@ -397,9 +398,11 @@
     }
     ui.game.finishStep = function() {
       board.putRandom(ui.board.position);
+      ui.board.turn++;
       ui.board.update(ui.board.position);
-      ui.score.update(ui.board.position);
+      ui.score.update(ui.board.position, ui.board.turn);
       localStorage.savedBoard = JSON.stringify(ui.board.position);
+      localStorage.savedTurn = ui.board.turn;
     }
 
     ////////////////////////////////////////////////////////////////
@@ -411,6 +414,7 @@
       ui.score.clear();
       ui.suggestion.clear();
       ui.game.clearMessage();
+      ui.board.turn = 0;
       ui.board.position = board.create();
       board.putRandom(ui.board.position);
       ui.board.update(ui.board.position);
@@ -592,7 +596,12 @@
     if (localStorage.savedBoard) {
       try {
         ui.board.position = JSON.parse(localStorage.savedBoard);
+        if (localStorage.savedTurn)
+          ui.board.turn = JSON.parse(localStorage.savedTurn);
+        else
+          ui.board.turn = 0;
         ui.board.update(ui.board.position);
+        ui.score.update(ui.board.position, ui.board.turn);
       } catch (ex) { }
     } else {
       ui.action.start();