Added statistics.

This commit is contained in:
Robert Kolner committed 2012-03-22 20:17:02 +01:00
1 parent f2c49ecc40
commit c392235b11
4 files changed
+44 -4

No files matched your search

+1 -1
View File
@@ -3,8 +3,8 @@
<script src="jquery-1.7.1.js"></script>
<script src="utils.js"></script>
<script src="tetris-canvas.js"></script>
<script src="tetris-stats.js"></script>
<script src="tetris.js"></script>
<!-- <script src="tetris-control.js"></script>-->
<script src="tetris-ai.js"></script>
<style>
+1
View File
@@ -3,6 +3,7 @@
<script src="jquery-1.7.1.js"></script>
<script src="utils.js"></script>
<script src="tetris-canvas.js"></script>
<script src="tetris-stats.js"></script>
<script src="tetris.js"></script>
<script src="tetris-control.js"></script>
+36
View File
@@ -0,0 +1,36 @@
function TetrisStats() {
this.countBrickTypes = Array(8);
this.countLineCombosCleared = Array(5);
this.countLinesCleared = 0;
this.newBrick = function(brickId) {
if (brickId < 0 || brickId > 7) {
return false;
}
this.countBrickTypes[brickId]++;
return true;
}
this.linesCleared = function(amount) {
if (amount < 0 || amount > 4) {
return false;
}
this.countLineCombosCleared[amount]++;
this.countLinesCleared += amount;
return true;
}
this.TetrisStats = function() {
for (var i = 0; i < this.countBrickTypes.length; i++) {
this.countBrickTypes[i] = 0;
}
for (var i = 0; i < this.countLineCombosCleared.length; i++) {
this.countLineCombosCleared[i] = 0;
}
}
this.TetrisStats();
}
+6 -3
View File
@@ -28,7 +28,8 @@ function TetrisGame(canvasId, linesCounterId, nextBricksCanvasId) {
/* Variables: */
/**************/
this.gameIsOver = false;
this.linesCleared = 0;
this.stats = new TetrisStats();
this.width = 10;
this.height = 15;
@@ -125,6 +126,7 @@ function TetrisGame(canvasId, linesCounterId, nextBricksCanvasId) {
this.currentBrickRot = 0;
this.currentBrickLoc = this.getBrickStartingLocation(this.currentBrickId);
this.stats.newBrick(this.currentBrickId);
this.redraw();
}
}
@@ -294,7 +296,7 @@ function TetrisGame(canvasId, linesCounterId, nextBricksCanvasId) {
this.updateLineCounter = function() {
if (this.lineCounterElement != 0) {
this.lineCounterElement.html('' +this.linesCleared);
this.lineCounterElement.html('' +this.stats.countLinesCleared);
}
}
@@ -310,9 +312,10 @@ function TetrisGame(canvasId, linesCounterId, nextBricksCanvasId) {
this.removeLine(filledLines[i]-i);
}
this.linesCleared += filledLines.length;
this.stats.linesCleared(filledLines.length);
this.updateLineCounter();
this.drawUnlock();
this.redraw();