2048.html
changeset 187 9520465a9c60
parent 176 c14dba10e59d
child 188 754796e567ab
equal deleted inserted replaced
186:dbf2da029e02 187:9520465a9c60
   147     </tr>
   147     </tr>
   148   </table>
   148   </table>
   149 
   149 
   150   <div id="control-area" class="area">
   150   <div id="control-area" class="area">
   151     <div class="control">
   151     <div class="control">
   152       <button id="start">Start</button>
   152       <button id="reset">Reset</button>
   153       <div class="option"><input type="checkbox" id="2048" checked> 2048</div>
   153       <div class="option"><input type="checkbox" id="2048" checked> 2048</div>
   154       <div class="option">
   154       <div class="option">
   155         <select id="board-engine">
   155         <select id="board-engine">
   156           <option value="BoardObj">BoardObj</option>
   156           <option value="BoardObj">BoardObj</option>
   157           <option value="BoardArr2d">BoardArr2d</option>
   157           <option value="BoardArr2d">BoardArr2d</option>
   567     ////////////////////////////////////////////////////////////////
   567     ////////////////////////////////////////////////////////////////
   568     // Actions.
   568     // Actions.
   569 
   569 
   570     ui.action = {};
   570     ui.action = {};
   571 
   571 
   572     ui.action.start = function() {
   572     ui.action.reset = function() {
   573       ui.score.clear();
   573       ui.score.clear();
   574       ui.suggestion.clear();
   574       ui.suggestion.clear();
   575       ui.game.clearMessage();
   575       ui.game.clearMessage();
   576       ui.board.turn = 0;
   576       ui.board.turn = 0;
   577       ui.board.position = board.create();
   577       ui.board.position = board.create();
   578       board.putRandom(ui.board.position);
   578       board.putRandom(ui.board.position);
   579       ui.board.update(ui.board.position);
   579       ui.board.update(ui.board.position);
   580     }
   580     }
   581     document.getElementById("start").addEventListener("click", ui.action.start, false);
   581     document.getElementById("reset").addEventListener("click", ui.action.reset, false);
   582 
   582 
   583     for (var i = 0; i < ui.game.dirs.length; i++) {
   583     for (var i = 0; i < ui.game.dirs.length; i++) {
   584       var dir = ui.game.dirs[i];
   584       var dir = ui.game.dirs[i];
   585       ui.action[dir] = function(dir) {
   585       ui.action[dir] = function(dir) {
   586         return function(event) {
   586         return function(event) {