-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
49 lines (46 loc) · 1.04 KB
/
map.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class Map {
constructor({ gridSize, cellSize }) {
this.size = gridSize;
this.cellSize = cellSize;
this.grid = new Array(this.size);
this.makeGrid();
this.startPoint = null;
this.targetPoint = null;
}
makeGrid() {
for (let i = 0; i < this.size; i++) {
this.grid[i] = new Array(this.size);
for (let j = 0; j < this.size; j++) {
this.grid[i][j] = new Cell({ row: i, col: j, size: this.cellSize });
}
}
}
draw() {
this.grid.forEach((row) => row.forEach((cell) => cell.draw()));
if (this.startPoint) {
fill(color(255));
rect(
this.startPoint.x,
this.startPoint.y,
this.cellSize,
this.cellSize,
5
);
}
if (this.targetPoint) {
fill(color(255, 235, 59));
rect(
this.targetPoint.x,
this.targetPoint.y,
this.cellSize,
this.cellSize,
5
);
}
}
updateCells() {
this.grid.forEach((row) =>
row.forEach((cell) => cell.updateNeighbors(this.grid))
);
}
}