tile.js 594 B

12345678910111213141516171819202122232425262728
  1. function Tile(position, value) {
  2. this.x = position.x;
  3. this.y = position.y;
  4. this.value = value || 2;
  5. this.previousPosition = null;
  6. this.mergedFrom = null; // Tracks tiles that merged together
  7. }
  8. Tile.prototype.savePosition = function () {
  9. this.previousPosition = { x: this.x, y: this.y };
  10. };
  11. Tile.prototype.updatePosition = function (position) {
  12. this.x = position.x;
  13. this.y = position.y;
  14. };
  15. Tile.prototype.serialize = function () {
  16. return {
  17. position: {
  18. x: this.x,
  19. y: this.y
  20. },
  21. value: this.value
  22. };
  23. };