34 lines
629 B
JavaScript
34 lines
629 B
JavaScript
var game = null;
|
|
|
|
function doTurn() {
|
|
document.onkeypress = onKeyPressed;
|
|
game.doTurn();
|
|
window.setTimeout(doTurn, 333);
|
|
}
|
|
|
|
function onKeyPressed(e) {
|
|
if (String.fromCharCode(e.charCode) == 'a') {
|
|
game.moveCurrentBrickHorizontally(-1);
|
|
return;
|
|
}
|
|
|
|
if (String.fromCharCode(e.charCode) == 'd') {
|
|
game.moveCurrentBrickHorizontally(1);
|
|
return;
|
|
}
|
|
|
|
if (String.fromCharCode(e.charCode) == 's') {
|
|
game.moveCurrentBrickDown();
|
|
return;
|
|
}
|
|
|
|
if (String.fromCharCode(e.charCode) == 'w') {
|
|
game.rotateCurrentBrick();
|
|
return;
|
|
}
|
|
}
|
|
|
|
$(document).ready(function() {
|
|
game = new TetrisGame("tetris-board");
|
|
doTurn();
|
|
}); |