Save board between browser sessions.
--- a/2048.html Wed Sep 10 20:16:06 2014 +0300
+++ b/2048.html Wed Sep 10 20:27:57 2014 +0300
@@ -398,7 +398,7 @@
board.putRandom(board.current);
ui.board.update(board.current);
ui.score.update(board.current);
- localStorage.savedBoard = board.current;
+ localStorage.savedBoard = JSON.stringify(board.current);
}
////////////////////////////////////////////////////////////////
@@ -587,8 +587,10 @@
ui.brdEngine = BoardArr2d; // TODO make user selectable
if (localStorage.savedBoard) {
- board.current = localStorage.savedBoard;
- ui.board.update(board.current);
+ try {
+ board.current = JSON.parse(localStorage.savedBoard);
+ ui.board.update(board.current);
+ } catch (ex) { }
} else {
ui.action.start();
}