From 4f0d922aa5ba80fa12348002d4fcb29f07d3d232 Mon Sep 17 00:00:00 2001 From: Robert Kolner Date: Tue, 13 Mar 2012 02:03:07 +0100 Subject: [PATCH] Added few more controls. --- tetris-control.js | 10 ++++++++++ tetris.js | 14 ++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/tetris-control.js b/tetris-control.js index 88cea34..1eba47a 100644 --- a/tetris-control.js +++ b/tetris-control.js @@ -16,6 +16,16 @@ function onKeyPressed(e) { 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() { diff --git a/tetris.js b/tetris.js index 13325eb..5cf8d24 100644 --- a/tetris.js +++ b/tetris.js @@ -112,6 +112,11 @@ function TetrisGame(id) { return true; } + this.canCurrentBrickRotate = function() { + /* TODO!! */ + return true; + } + this.moveCurrentBrickHorizontally = function(dx) { if (this.canCurrentBrickMove(dx, 0)) { this.currentBrickLoc[0] += dx; @@ -141,6 +146,15 @@ function TetrisGame(id) { return false; } + this.rotateCurrentBrick = function() { + if (this.canCurrentBrickRotate()) { + this.currentBrickRot = (this.currentBrickRot + 1) % 4; + this.redraw(); + return true; + } + return false; + } + this.doTurn = function() { /* Fill out */ this.moveCurrentBrickDown();