xxxxxxxxxx
30
class Tile {
constructor(x, y, w, n) {
this.x = x;
this.y = y;
this.n = n;
this.w = w;
}
show() {
fill("#AAA");
square(this.x, this.y, this.w);
fill("#000");
textAlign(CENTER, CENTER);
text(this.n, this.x + this.w / 2, this.y + this.w / 2);
}
clicked(x, y, empty) {
if (!(x < this.x || x > this.x + this.w || y < this.y || y > this.y + this.w)) {
x = empty.x;
y = empty.y
if (!((this.x - this.w === x || this.x + this.w === x) && (this.y - this.w === y || this.y + this.w === y))) {
const oldPos = {x: this.x, y: this.y}
this.x = x
this.y = y
return oldPos;
}
}
return null;
}
}