Skip to content

Commit

Permalink
Create tile.js
Browse files Browse the repository at this point in the history
  • Loading branch information
CBGamesdev committed Sep 16, 2021
1 parent 94a2e7e commit eb28f41
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 2048/js/tile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
function Tile(position, value) {
this.x = position.x;
this.y = position.y;
this.value = value || 2;

this.previousPosition = null;
this.mergedFrom = null; // Tracks tiles that merged together
}

Tile.prototype.savePosition = function () {
this.previousPosition = { x: this.x, y: this.y };
};

Tile.prototype.updatePosition = function (position) {
this.x = position.x;
this.y = position.y;
};

Tile.prototype.clone = function() {
newTile = new Tile({ x: this.x, y: this.y }, this.value);
//newTile.previousPosition = { x: this.previousPosition.x, y: this.previousPosition.y };
//newTile.mergedFrom = { x: this.previousPosition.x, y: this.previousPosition.y };
return newTile;
}

0 comments on commit eb28f41

Please sign in to comment.