2048.html
changeset 113 fc058d27e829
parent 112 4bb8ed8448bc
child 123 fc6019d22a38
equal deleted inserted replaced
112:4bb8ed8448bc 113:fc058d27e829
   141 
   141 
   142   <div id="control-area" class="area">
   142   <div id="control-area" class="area">
   143     <div class="control">
   143     <div class="control">
   144       <button id="start">Start</button>
   144       <button id="start">Start</button>
   145       <div class="option"><input type="checkbox" id="2048" checked> 2048</div>
   145       <div class="option"><input type="checkbox" id="2048" checked> 2048</div>
       
   146       <div class="option">
       
   147         <select id="board-engine">
       
   148           <option value="BoardObj">BoardObj</option>
       
   149           <option value="BoardArr2d">BoardArr2d</option>
       
   150           <option value="BoardArr">BoardArr</option>
       
   151         </select> engine
       
   152       </div>
   146     </div>
   153     </div>
   147     <br>
   154     <br>
   148     <div class="control">
   155     <div class="control">
   149       <button id="suggest">Suggest</button>
   156       <button id="suggest">Suggest</button>
   150       <button id="step">Step</button>
   157       <button id="step">Step</button>
   333     ui.board.val2048 = function(val) {
   340     ui.board.val2048 = function(val) {
   334       if (ui.board.val2048Dom.checked)
   341       if (ui.board.val2048Dom.checked)
   335         return Math.pow(2, val);
   342         return Math.pow(2, val);
   336       return val;
   343       return val;
   337     }
   344     }
       
   345     var boardEngineDom = document.getElementById("board-engine");
       
   346     boardEngineDom.addEventListener("change", function() {
       
   347       var engine = boardEngineDom.value;
       
   348       ui.brdEngine = window[engine];
       
   349       localStorage.brdEngine = engine;
       
   350     });
   338     /* 'val' typesafe.  */
   351     /* 'val' typesafe.  */
   339     ui.board.set = function(i, j, val) {
   352     ui.board.set = function(i, j, val) {
   340       if (typeof val !== 'number')
   353       if (typeof val !== 'number')
   341         val = 0;
   354         val = 0;
   342       var dom = boardDom.querySelectorAll("tr")[i].querySelectorAll("td")[j];
   355       var dom = boardDom.querySelectorAll("tr")[i].querySelectorAll("td")[j];
   907     statisticCleanBtn.addEventListener("click", ui.report.statClean, false);
   920     statisticCleanBtn.addEventListener("click", ui.report.statClean, false);
   908 
   921 
   909     ////////////////////////////////////////////////////////////////
   922     ////////////////////////////////////////////////////////////////
   910     // Initialise game.
   923     // Initialise game.
   911 
   924 
   912     ui.brdEngine = BoardArr2d; // TODO make user selectable
   925     if (localStorage.brdEngine) {
   913     // ui.brdEngine = BoardObj; // TODO make user selectable
   926       boardEngineDom.value = localStorage.brdEngine;
       
   927       ui.brdEngine = window[localStorage.brdEngine];
       
   928     } else {
       
   929       ui.brdEngine = BoardArr2d;
       
   930     }
   914 
   931 
   915     if (localStorage.untilScore) {
   932     if (localStorage.untilScore) {
   916       var scoreLimit = parseInt(localStorage.untilScore);
   933       var scoreLimit = parseInt(localStorage.untilScore);
   917       if (isFinite(scoreLimit) && scoreLimit > 0)
   934       if (isFinite(scoreLimit) && scoreLimit > 0)
   918         document.getElementById("until-score").value = scoreLimit;
   935         document.getElementById("until-score").value = scoreLimit;