90 lines
1.6 KiB
JavaScript
90 lines
1.6 KiB
JavaScript
|
|
class Cell {
|
|
|
|
constructor(x, y, cellWidth){
|
|
this.x = x;
|
|
this.y = y;
|
|
this.walls = [true, true, true, true];
|
|
this.selected = false;
|
|
this.visited = false;
|
|
this.cellWidth = cellWidth;
|
|
this.searched = false;
|
|
this.finalPath = false;
|
|
this.parent = undefined;
|
|
this.end = false;
|
|
this.start = false;
|
|
}
|
|
|
|
get top(){
|
|
return this.walls[0];
|
|
}
|
|
|
|
set setTop(removed){
|
|
this.walls[0] = removed;
|
|
}
|
|
|
|
get left(){
|
|
return this.walls[1];
|
|
}
|
|
|
|
set setLeft(removed){
|
|
this.walls[1] = removed;
|
|
}
|
|
|
|
get bottom(){
|
|
return this.walls[2];
|
|
}
|
|
|
|
set setBottom(removed){
|
|
this.walls[2] = removed;
|
|
}
|
|
|
|
get right(){
|
|
return this.walls[3];
|
|
}
|
|
|
|
set setRight(removed){
|
|
this.walls[3] = removed;
|
|
}
|
|
|
|
show(){
|
|
let x = this.x * this.cellWidth;
|
|
let y = this.y * this.cellWidth;
|
|
|
|
stroke(0);
|
|
|
|
if (this.top) line(x, y, x + this.cellWidth, y);
|
|
if (this.right) line(x + this.cellWidth, y, x + this.cellWidth, y + this.cellWidth);
|
|
if (this.bottom) line(x + this.cellWidth, y + this.cellWidth, x, y + this.cellWidth);
|
|
if (this.left) line(x, y, x, y + this.cellWidth);
|
|
|
|
if (this.visited) {
|
|
fill(255, 0, 0);
|
|
noStroke();
|
|
rect(x, y, this.cellWidth, this.cellWidth);
|
|
}
|
|
|
|
if(this.searched){
|
|
fill(210, 180, 140);
|
|
noStroke();
|
|
rect(x, y, this.cellWidth, this.cellWidth);
|
|
}
|
|
|
|
if (this.selected) {
|
|
fill(50, 125, 0);
|
|
noStroke();
|
|
rect(x, y, this.cellWidth, this.cellWidth);
|
|
}
|
|
|
|
if(this.finalPath){
|
|
fill(173, 216, 230);
|
|
noStroke();
|
|
rect(x, y, this.cellWidth, this.cellWidth);
|
|
}
|
|
|
|
if(this.start){
|
|
text("Start", x, y + cellWidth / 2);
|
|
}
|
|
}
|
|
}
|