add score and endgame

This commit is contained in:
Gabriele Cirulli
2014-03-09 23:03:13 +01:00
parent 53e08722e0
commit f18f7cee22
5 changed files with 271 additions and 54 deletions
+18 -2
View File
@@ -1,8 +1,10 @@
function HTMLActuator() {
this.tileContainer = document.getElementsByClassName("tile-container")[0];
this.tileContainer = document.getElementsByClassName("tile-container")[0];
this.gameContainer = document.getElementsByClassName("game-container")[0];
this.scoreContainer = document.getElementsByClassName("score-container")[0];
}
HTMLActuator.prototype.actuate = function (grid) {
HTMLActuator.prototype.actuate = function (grid, metadata) {
var self = this;
window.requestAnimationFrame(function () {
@@ -15,6 +17,12 @@ HTMLActuator.prototype.actuate = function (grid) {
}
});
});
self.updateScore(metadata.score);
if (metadata.over) {
self.gameOver();
}
});
};
@@ -59,3 +67,11 @@ HTMLActuator.prototype.positionClass = function (position) {
position = this.normalizePosition(position);
return "tile-position-" + position.x + "-" + position.y;
};
HTMLActuator.prototype.updateScore = function (score) {
this.scoreContainer.textContent = score;
};
HTMLActuator.prototype.gameOver = function () {
this.gameContainer.classList.add("game-over");
};