# HG changeset patch # User Oleksandr Gavenko # Date 1410389274 -10800 # Node ID 0bcdec3bdaa861e86a237d8723a586a186b34117 # Parent 518ab579d24b8b79cdf3e325a24ee307b73ca8fa Rename. diff -r 518ab579d24b -r 0bcdec3bdaa8 2048.html --- a/2048.html Thu Sep 11 01:35:56 2014 +0300 +++ b/2048.html Thu Sep 11 01:47:54 2014 +0300 @@ -235,7 +235,7 @@ ui.board = {}; ui.board.val2048Dom = document.getElementById('2048'); ui.board.val2048Dom.addEventListener("click", function(event) { - ui.board.update(board.current); + ui.board.update(ui.board.position); localStorage.val2048 = ui.board.val2048Dom.checked; event.target.blur(); }); @@ -270,7 +270,7 @@ if (tdDom.firstChild) tdDom.removeChild(tdDom.firstChild); var inputDom = document.createElement('input'); - inputDom.value = board.current[i][j]; + inputDom.value = ui.board.position[i][j]; inputDom.style.width = '1em'; tdDom.appendChild(inputDom); inputDom.focus(); @@ -285,10 +285,10 @@ var inputDom = tdDom.firstChild; var val = parseInt(inputDom.value); if (0 <= val && val < 15) { - board.current[i][j] = val; + ui.board.position[i][j] = val; ui.board.set(i, j, val); } else { - ui.board.set(i, j, board.current[i][j]); + ui.board.set(i, j, ui.board.position[i][j]); } } } @@ -367,7 +367,7 @@ } ui.game.checkGameOver = function() { - if (board.gameOver(board.current)) { + if (board.gameOver(ui.board.position)) { ui.game.setMessage("Game over!"); return true; } else { @@ -376,7 +376,7 @@ } ui.game.checkMoveValid = function(move) { var tmpBrd = board.create(); - board.copy(board.current, tmpBrd); + board.copy(ui.board.position, tmpBrd); if (ui.game.dirs.indexOf(move) === -1) { ui.game.setMessage("AI can't find move!"); return false; @@ -396,10 +396,10 @@ return true; } ui.game.finishStep = function() { - board.putRandom(board.current); - ui.board.update(board.current); - ui.score.update(board.current); - localStorage.savedBoard = JSON.stringify(board.current); + board.putRandom(ui.board.position); + ui.board.update(ui.board.position); + ui.score.update(ui.board.position); + localStorage.savedBoard = JSON.stringify(ui.board.position); } //////////////////////////////////////////////////////////////// @@ -411,9 +411,9 @@ ui.score.clear(); ui.suggestion.clear(); ui.game.clearMessage(); - board.current = board.create(); - board.putRandom(board.current); - ui.board.update(board.current); + ui.board.position = board.create(); + board.putRandom(ui.board.position); + ui.board.update(ui.board.position); } document.getElementById("start").addEventListener("click", ui.action.start); @@ -424,7 +424,7 @@ if (ui.game.checkGameOver()) return; ui.suggestion.clear(); - var updated = board.move[dir](board.current); + var updated = board.move[dir](ui.board.position); if (updated) { ui.game.finishStep(); ui.ai.current && ui.ai.current.cleanup(); @@ -457,7 +457,7 @@ if ( ! ui.game.beginStep()) return; var tmpBrd = board.create(); - board.copy(board.current, tmpBrd); + board.copy(ui.board.position, tmpBrd); var move = ui.ai.current.analyse(tmpBrd); ui.ai.current.cleanup(); if ( ! ui.game.checkMoveValid(move)) @@ -473,12 +473,12 @@ if ( ! ui.game.beginStep()) return; var tmpBrd = board.create(); - board.copy(board.current, tmpBrd); + board.copy(ui.board.position, tmpBrd); var move = ui.ai.current.analyse(tmpBrd); ui.ai.current.cleanup(); if ( ! ui.game.checkMoveValid(move)) return; - board.move[move].call(null, board.current); + board.move[move].call(null, ui.board.position); ui.game.finishStep(); } document.getElementById("step").addEventListener("click", ui.action.step); @@ -491,17 +491,17 @@ ui.game.beginStep(); var step = 0; var tsFrom = new Date().getTime(); - while (!board.gameOver(board.current)) { + while (!board.gameOver(ui.board.position)) { var tmpBrd = board.create(); - board.copy(board.current, tmpBrd); + board.copy(ui.board.position, tmpBrd); var move = ui.ai.current.analyse(tmpBrd); if (typeof move === 'undefined') { ui.game.setMessage("I don't know how to move!"); return; } - var updated = board.move[move].call(null, board.current); + var updated = board.move[move].call(null, ui.board.position); if (updated) { - board.putRandom(board.current); + board.putRandom(ui.board.position); } else { ui.game.finishStep(); ui.game.setMessage("Wrong move!"); @@ -591,8 +591,8 @@ } if (localStorage.savedBoard) { try { - board.current = JSON.parse(localStorage.savedBoard); - ui.board.update(board.current); + ui.board.position = JSON.parse(localStorage.savedBoard); + ui.board.update(ui.board.position); } catch (ex) { } } else { ui.action.start();