2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 10 Sep 2014 18:05:26 +0300
changeset 38 d476efde7242
parent 37 fe75d168a605
child 39 a75cc5aa5d19
2 modes of value showing: 0,1,...,11 and 0,2,4,...,2048.
2048.html
--- a/2048.html	Wed Sep 10 17:33:04 2014 +0300
+++ b/2048.html	Wed Sep 10 18:05:26 2014 +0300
@@ -132,6 +132,7 @@
   <div id="control-area" class="area">
     <div>
       <button id="start">Start</button>
+      <span><input type="checkbox" id="2048" checked> 2048</span>
     </div>
     <div class="ai-control">
       <button id="suggest">Suggest</button>
@@ -232,13 +233,23 @@
     var boardDom = document.getElementById("board");
     var ui = {};
     ui.board = {};
+    ui.board.val2048Dom = document.getElementById('2048');
+    ui.board.val2048Dom.addEventListener("click", function(event) {
+      ui.board.update(board.current);
+      event.target.blur();
+    });
+    ui.board.val2048 = function(val) {
+      if (ui.board.val2048Dom.checked)
+        return Math.pow(2, val);
+      return val;
+    }
     /* 'val' typesafe.  */
     ui.board.set = function(i, j, val) {
       if (typeof val !== 'number')
         val = 0;
       var dom = boardDom.querySelectorAll("tr")[i].querySelectorAll("td")[j];
       if (0 < val && val < 15) {
-        dom.innerHTML = val;
+        dom.innerHTML = ui.board.val2048(val);
         var rgb = 'rgb(255,'+ (255-5*val-2*(val%2)) +','+ (255-10*val-5*((val-1)%2)) +')';
       } else {
         dom.innerHTML = '';