From 5c98519d2f7c92b2260d7adf3b7cdb03193ea0fa Mon Sep 17 00:00:00 2001 From: Robert Kolner Date: Mon, 12 Mar 2012 23:40:50 +0100 Subject: [PATCH] Send size of the board as parameters. --- tetris-canvas.js | 6 +++--- tetris.js | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tetris-canvas.js b/tetris-canvas.js index ba9a6a5..c21502c 100644 --- a/tetris-canvas.js +++ b/tetris-canvas.js @@ -1,4 +1,4 @@ -function TetrisCanvas(id) { +function TetrisCanvas(id, width, height) { /***********/ /* Colors: */ /***********/ @@ -25,8 +25,8 @@ function TetrisCanvas(id) { this.context = null; /* Segment-dependant: */ - this.sWidth = 10; - this.sHeight = 15; + this.sWidth = width; + this.sHeight = height; /**************/ /* Functions: */ diff --git a/tetris.js b/tetris.js index 497e590..0f35714 100644 --- a/tetris.js +++ b/tetris.js @@ -1,27 +1,27 @@ function TetrisGame(id) { + this.width = 10; + this.height = 15; + this.canvas = new TetrisCanvas(id); + this.board = createArray(this.width, this.height); + + this.doTurn = function() { + this.canvas.drawBoard(this.board); + } this.TetrisGame = function(id) { - var canvas = new TetrisCanvas(id); - var board = createArray(10,15); - + this.canvas = new TetrisCanvas(id, this.width, this.height); + this.board = createArray(this.width, this.height); for (var y = 0; y < 15; y++) { for (var x = 0; x < 10; x++) { - board[x][y] = 0; + this.board[x][y] = 0; } } - - board[1][1] = 'I'; - board[2][1] = 'J'; - board[3][1] = 'L'; - board[4][1] = 'O'; - board[5][1] = 'S'; - board[6][1] = 'T'; - board[7][1] = 'Z'; - canvas.drawBoard(board); }; this.TetrisGame(id); } $(document).ready(function() { - new TetrisGame("tetris-board"); + var tetris = new TetrisGame("tetris-board"); + tetris.board[1][1] = 'I'; + tetris.doTurn(); }); \ No newline at end of file