Added score.
This commit is contained in:
1 parent
24cdb2715f
commit
59a7eb083f
1 file changed
+17
-1
@@ -28,7 +28,9 @@ function TetrisGame(id) {
|
|||||||
/* Variables: */
|
/* Variables: */
|
||||||
/**************/
|
/**************/
|
||||||
this.gameIsOver = false;
|
this.gameIsOver = false;
|
||||||
|
this.gameLinesCleared = 0;
|
||||||
|
this.gameScore = 0;
|
||||||
|
|
||||||
this.width = 10;
|
this.width = 10;
|
||||||
this.height = 15;
|
this.height = 15;
|
||||||
this.canvas = new TetrisCanvas(id, this.width, this.height);
|
this.canvas = new TetrisCanvas(id, this.width, this.height);
|
||||||
@@ -54,6 +56,17 @@ function TetrisGame(id) {
|
|||||||
this.drawCurrentBrick();
|
this.drawCurrentBrick();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.xyToTileIndex = function(x,y) {
|
||||||
|
return y * this.width + x;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.tileIndexToXY = function(tileIndex) {
|
||||||
|
var y = Math.floor(tileIndex / this.width);
|
||||||
|
var x = tileIndex % y;
|
||||||
|
|
||||||
|
return [x,y];
|
||||||
|
}
|
||||||
|
|
||||||
this.getRandomBrick = function() {
|
this.getRandomBrick = function() {
|
||||||
return 1 + Math.floor(Math.random() * 7);
|
return 1 + Math.floor(Math.random() * 7);
|
||||||
}
|
}
|
||||||
@@ -253,6 +266,9 @@ function TetrisGame(id) {
|
|||||||
for (var i = 0; i < filledLines.length; i++) {
|
for (var i = 0; i < filledLines.length; i++) {
|
||||||
this.removeLine(filledLines[i]-i);
|
this.removeLine(filledLines[i]-i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.gameScore += filledLines.length * 100;
|
||||||
|
this.gameLinesCleared += filledLines.length;
|
||||||
this.drawUnlock();
|
this.drawUnlock();
|
||||||
this.redraw();
|
this.redraw();
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user