add movement check, score addition

This commit is contained in:
Gabriele Cirulli
2014-03-09 23:24:17 +01:00
parent f18f7cee22
commit 4b3055fcd0
4 changed files with 94 additions and 6 deletions
+20 -5
View File
@@ -2,13 +2,15 @@ function HTMLActuator() {
this.tileContainer = document.getElementsByClassName("tile-container")[0];
this.gameContainer = document.getElementsByClassName("game-container")[0];
this.scoreContainer = document.getElementsByClassName("score-container")[0];
this.score = 0;
}
HTMLActuator.prototype.actuate = function (grid, metadata) {
var self = this;
window.requestAnimationFrame(function () {
self.clearContainer();
self.clearContainer(self.tileContainer);
grid.cells.forEach(function (column) {
column.forEach(function (cell) {
@@ -26,9 +28,9 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
});
};
HTMLActuator.prototype.clearContainer = function () {
while (this.tileContainer.firstChild) {
this.tileContainer.removeChild(this.tileContainer.firstChild);
HTMLActuator.prototype.clearContainer = function (container) {
while (container.firstChild) {
container.removeChild(container.firstChild);
}
};
@@ -69,7 +71,20 @@ HTMLActuator.prototype.positionClass = function (position) {
};
HTMLActuator.prototype.updateScore = function (score) {
this.scoreContainer.textContent = score;
this.clearContainer(this.scoreContainer);
var difference = score - this.score;
this.score = score;
this.scoreContainer.textContent = this.score;
if (difference) {
var addition = document.createElement("div");
addition.classList.add("score-addition");
addition.textContent = "+" + difference;
this.scoreContainer.appendChild(addition);
}
};
HTMLActuator.prototype.gameOver = function () {