Moved some code.
This commit is contained in:
1 parent
8526bfd916
commit
41a813de13
2 files changed
+22
-23
No files matched your search
+7
-18
@@ -1,4 +1,4 @@
|
|||||||
function TetrisCanvas(id, width, height, linesId) {
|
function TetrisCanvas(canvasId, width, height) {
|
||||||
/***********/
|
/***********/
|
||||||
/* Colors: */
|
/* Colors: */
|
||||||
/***********/
|
/***********/
|
||||||
@@ -28,9 +28,6 @@ function TetrisCanvas(id, width, height, linesId) {
|
|||||||
this.sWidth = width;
|
this.sWidth = width;
|
||||||
this.sHeight = height;
|
this.sHeight = height;
|
||||||
|
|
||||||
/* Score box: */
|
|
||||||
this.linesElement = 0;
|
|
||||||
|
|
||||||
/**************/
|
/**************/
|
||||||
/* Functions: */
|
/* Functions: */
|
||||||
/**************/
|
/**************/
|
||||||
@@ -54,27 +51,19 @@ function TetrisCanvas(id, width, height, linesId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateLines = function(newLines) {
|
|
||||||
if (this.linesElement != 0) {
|
|
||||||
this.linesElement.html(newLines);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/***************/
|
/***************/
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
/***************/
|
/***************/
|
||||||
this.TetrisCanvas = function(id, linesId) {
|
this.TetrisCanvas = function(canvasId) {
|
||||||
var canvas = document.getElementById(id);
|
var canvas = document.getElementById(canvasId);
|
||||||
this.pxHeight = $("#"+id).height();
|
this.pxHeight = $("#"+canvasId).height();
|
||||||
this.pxWidth = $("#"+id).width();
|
this.pxWidth = $("#"+canvasId).width();
|
||||||
this.pxRectSize = (this.pxWidth - (this.pxSeparatorSize * this.sWidth)) / (this.sWidth);
|
this.pxRectSize = (this.pxWidth - (this.pxSeparatorSize * this.sWidth)) / (this.sWidth);
|
||||||
|
|
||||||
this.context = canvas.getContext("2d");
|
this.context = canvas.getContext("2d");
|
||||||
|
|
||||||
if (linesId) {
|
|
||||||
this.linesElement = $("#"+linesId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.TetrisCanvas(id, linesId);
|
this.TetrisCanvas(canvasId);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
function TetrisGame(id, linesId) {
|
function TetrisGame(canvasId, linesCounterId, nextBricksCanvasId) {
|
||||||
/*********/
|
/*********/
|
||||||
/* Enum: */
|
/* Enum: */
|
||||||
/*********/
|
/*********/
|
||||||
@@ -32,7 +32,8 @@ function TetrisGame(id, linesId) {
|
|||||||
|
|
||||||
this.width = 10;
|
this.width = 10;
|
||||||
this.height = 15;
|
this.height = 15;
|
||||||
this.canvas = new TetrisCanvas(id, this.width, this.height, linesId);
|
this.canvas = new TetrisCanvas(canvasId, this.width, this.height, linesCounterId, nextBricksCanvasId);
|
||||||
|
this.lineCounterElement = 0;
|
||||||
this.board = createArray(this.width, this.height);
|
this.board = createArray(this.width, this.height);
|
||||||
|
|
||||||
this.currentBrickId = 0;
|
this.currentBrickId = 0;
|
||||||
@@ -265,6 +266,12 @@ function TetrisGame(id, linesId) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateLineCounter = function() {
|
||||||
|
if (this.lineCounterElement != 0) {
|
||||||
|
this.lineCounterElement.html('' +this.linesCleared);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.doTurn = function() {
|
this.doTurn = function() {
|
||||||
this.drawLock();
|
this.drawLock();
|
||||||
@@ -279,7 +286,7 @@ function TetrisGame(id, linesId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.linesCleared += filledLines.length;
|
this.linesCleared += filledLines.length;
|
||||||
this.canvas.updateLines(this.linesCleared);
|
this.updateLineCounter();
|
||||||
|
|
||||||
this.drawUnlock();
|
this.drawUnlock();
|
||||||
this.redraw();
|
this.redraw();
|
||||||
@@ -303,7 +310,10 @@ function TetrisGame(id, linesId) {
|
|||||||
/****************/
|
/****************/
|
||||||
/* Constructor: */
|
/* Constructor: */
|
||||||
/****************/
|
/****************/
|
||||||
this.TetrisGame = function(id) {
|
this.TetrisGame = function() {
|
||||||
|
// Find the line counter element if defined:
|
||||||
|
this.lineCounterElement = $('#' +linesCounterId);
|
||||||
|
|
||||||
// Initialize the board:
|
// Initialize the board:
|
||||||
for (var y = 0; y < 15; y++) {
|
for (var y = 0; y < 15; y++) {
|
||||||
for (var x = 0; x < 10; x++) {
|
for (var x = 0; x < 10; x++) {
|
||||||
@@ -318,5 +328,5 @@ function TetrisGame(id, linesId) {
|
|||||||
|
|
||||||
this.getNextCurrentBrick();
|
this.getNextCurrentBrick();
|
||||||
};
|
};
|
||||||
this.TetrisGame(id);
|
this.TetrisGame();
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user