2048.html
changeset 44 518ab579d24b
parent 43 8b1577211149
child 45 0bcdec3bdaa8
equal deleted inserted replaced
43:8b1577211149 44:518ab579d24b
   434       document.getElementById(dir).addEventListener("click", ui.action[dir]);
   434       document.getElementById(dir).addEventListener("click", ui.action[dir]);
   435     }
   435     }
   436 
   436 
   437     document.body.addEventListener("keydown", function(event) {
   437     document.body.addEventListener("keydown", function(event) {
   438       if (document.activeElement.value)
   438       if (document.activeElement.value)
   439         return false;
   439         return;
   440       var key = event.keyCode || event.which;
   440       var key = event.keyCode || event.which;
   441       switch (key) {
   441       var keyMoves = {38: "up", 40: "down", 37: "left", 39: "right"};
   442           case 38: ui.action.up(); break;
   442       if (key in keyMoves) {
   443           case 40: ui.action.down(); break;
   443         ui.action[keyMoves[key]]();
   444           case 37: ui.action.left(); break;
   444         event.preventDefault();
   445           case 39: ui.action.right(); break;
   445       }
   446       }
       
   447       event.preventDefault();
       
   448       return false;
       
   449     });
   446     });
   450 
   447 
   451     document.getElementById("test").addEventListener("click", function() {
   448     document.getElementById("test").addEventListener("click", function() {
   452       board.move.replaceByBoardJS(ui.brdEngine);
   449       board.move.replaceByBoardJS(ui.brdEngine);
   453     });
   450     });