From 49355f203fdb478770af1bfe172de3a0e298f0de Mon Sep 17 00:00:00 2001 From: Robert Kolner Date: Tue, 13 Mar 2012 17:50:21 +0100 Subject: [PATCH] Generalized a method. --- tetris.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tetris.js b/tetris.js index 5cf8d24..3a19cbc 100644 --- a/tetris.js +++ b/tetris.js @@ -55,12 +55,12 @@ function TetrisGame(id) { this.redraw(); } - this.currentBrickShape = function() { - var glob_shape = this.brickShapes[this.currentBrickId]; + this.brickShape = function(brickId, brickRot) { + var glob_shape = this.brickShapes[brickId]; var shape = createArray(4,2); for (var i = 0; i < 4; i++) { - switch(this.currentBrickRot) { + switch(brickRot) { case 0: shape[i][0] = glob_shape[i][0]; shape[i][1] = glob_shape[i][1]; @@ -84,7 +84,7 @@ function TetrisGame(id) { } this.drawCurrentBrick = function() { - var shape = this.currentBrickShape(); + var shape = this.brickShape(this.currentBrickId, this.currentBrickRot); for (var i = 0; i < 4; i++) { var x = this.currentBrickLoc[0]+shape[i][0]; @@ -94,7 +94,7 @@ function TetrisGame(id) { } this.canCurrentBrickMove = function(dx,dy) { - var shape = this.currentBrickShape(); + var shape = this.brickShape(this.currentBrickId, this.currentBrickRot); for (var i = 0; i < 4; i++) { var x = this.currentBrickLoc[0]+shape[i][0] + dx; @@ -134,7 +134,7 @@ function TetrisGame(id) { } // If not, integrate into board: - var shape = this.currentBrickShape(); + var shape = this.brickShape(this.currentBrickId, this.currentBrickRot); for (var i = 0; i < 4; i++) { var x = this.currentBrickLoc[0]+shape[i][0]; var y = this.currentBrickLoc[1]+shape[i][1];