merge infinite game

This commit is contained in:
Gabriele Cirulli
2014-03-14 13:22:29 +01:00
6 changed files with 57 additions and 6 deletions
+13 -3
View File
@@ -24,8 +24,11 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
self.updateScore(metadata.score);
self.updateBestScore(metadata.bestScore);
if (metadata.over) self.message(false); // You lose
if (metadata.won) self.message(true); // You win!
if (metadata.gameOver) {
if (metadata.over) self.message(false); // You lose
else if (metadata.won) self.message(true); // You win!
}
});
};
@@ -33,6 +36,10 @@ HTMLActuator.prototype.restart = function () {
this.clearMessage();
};
HTMLActuator.prototype.keepPlaying = function () {
this.clearMessage();
};
HTMLActuator.prototype.clearContainer = function (container) {
while (container.firstChild) {
container.removeChild(container.firstChild);
@@ -45,10 +52,13 @@ HTMLActuator.prototype.addTile = function (tile) {
var wrapper = document.createElement("div");
var inner = document.createElement("div");
var position = tile.previousPosition || { x: tile.x, y: tile.y };
positionClass = this.positionClass(position);
var positionClass = this.positionClass(position);
// We can't use classlist because it somehow glitches when replacing classes
var classes = ["tile", "tile-" + tile.value, positionClass];
if (tile.value > 2048) classes.push("tile-gold");
this.applyClasses(wrapper, classes);
inner.classList.add("tile-inner");