xxxxxxxxxx
83
class Tile {
constructor(_x, _y) {
this.x = _x;
this.y = _y;
this.neighbors = [];
this.selected = false;
this.adjacencyList = new Map();
}
addNeighbor(neighbor) {
let match = false;
this.neighbors.forEach((n) => {
if (JSON.stringify(n) === JSON.stringify(neighbor)) {
console.log("MATCH");
match = true;
}
});
if (match) {
this.neighbors = this.neighbors.filter((n) =>{
return JSON.stringify(n) !== JSON.stringify(neighbor);
});
} else {
this.neighbors.push(neighbor);
}
this.adjacencyList.set(this.adjacencyList.size, new Set([neighbor.x,neighbor.y]));
console.log(this.adjacencyList);
}
showNeighbors() {
if (this.selected) {
fill(255, 0, 0,100);
noStroke();
for (let neighbor of this.neighbors) {
rect(
neighbor.x * size * zoom,
neighbor.y * size * zoom,
size * zoom,
size * zoom
);
}
}
}
showSelected() {
if (this.selected) {
strokeWeight(3);
stroke(0, 255, 0);
fill(0, 255, 0,100);
rect(
this.x * size * zoom,
this.y * size * zoom,
size * zoom,
size * zoom
);
} else {
if (this.neighbors.length > 0) {
noStroke();
fill(32, 127);
rect(
this.x * size * zoom,
this.y * size * zoom,
size * zoom,
size * zoom
);
}
}
}
select() {
this.selected = true;
}
deselect() {
this.selected = false;
}
isSelected() {
return this.selected;
}
}