add tile merging

This commit is contained in:
Gabriele Cirulli
2014-03-09 20:03:04 +01:00
parent efa2af59a2
commit 53e08722e0
7 changed files with 157 additions and 58 deletions
+14 -1
View File
@@ -62,10 +62,23 @@ Grid.prototype.cellOccupied = function (cell) {
};
Grid.prototype.cellContent = function (cell) {
return this.cells[cell.x][cell.y];
if (this.withinBounds(cell)) {
return this.cells[cell.x][cell.y];
} else {
return null;
}
};
// Inserts a tile at its position
Grid.prototype.insertTile = function (tile) {
this.cells[tile.x][tile.y] = tile;
};
Grid.prototype.removeTile = function (tile) {
this.cells[tile.x][tile.y] = null;
};
Grid.prototype.withinBounds = function (position) {
return position.x >= 0 && position.x < this.size &&
position.y >= 0 && position.y < this.size;
};