Send size of the board as parameters.
This commit is contained in:
1 parent
291258ebb0
commit
5c98519d2f
2 files changed
+17
-17
No files matched your search
+3
-3
@@ -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: */
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
Reference in new issue
Block a user