2014-03-08 12:50:45 +01:00
|
|
|
function HTMLActuator() {
|
2014-03-08 13:32:37 +01:00
|
|
|
this.tileContainer = document.getElementsByClassName("tile-container")[0];
|
2014-03-08 12:50:45 +01:00
|
|
|
}
|
|
|
|
|
2014-03-08 13:10:54 +01:00
|
|
|
HTMLActuator.prototype.actuate = function (grid) {
|
2014-03-08 13:32:37 +01:00
|
|
|
var self = this;
|
|
|
|
|
|
|
|
this.clearContainer();
|
|
|
|
|
|
|
|
grid.cells.forEach(function (column) {
|
|
|
|
column.forEach(function (cell) {
|
|
|
|
if (cell) {
|
|
|
|
self.addTile(cell);
|
|
|
|
}
|
|
|
|
});
|
2014-03-08 12:50:45 +01:00
|
|
|
});
|
|
|
|
};
|
2014-03-08 13:32:37 +01:00
|
|
|
|
|
|
|
HTMLActuator.prototype.clearContainer = function () {
|
|
|
|
while (this.tileContainer.firstChild) {
|
|
|
|
this.tileContainer.removeChild(this.tileContainer.firstChild);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
HTMLActuator.prototype.addTile = function (tile) {
|
|
|
|
var element = document.createElement("div");
|
|
|
|
|
|
|
|
var x = tile.x + 1;
|
|
|
|
var y = tile.y + 1;
|
|
|
|
var position = "tile-position-" + x + "-" + y;
|
|
|
|
|
|
|
|
element.classList.add("tile", "tile-" + tile.value, position);
|
|
|
|
element.textContent = tile.value;
|
|
|
|
|
|
|
|
this.tileContainer.appendChild(element);
|
|
|
|
};
|