-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maze.js
37 lines (31 loc) · 840 Bytes
/
Maze.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
let Vec = require("./Vec");
class Maze {
/**
*
* @param {Vec} size
*/
constructor(size) {
this.size = size;
this.mazeStruckture = [];
// generate...
}
generateMaze() {
for (let i = 0; i < size.x * size.y; i++) {
mazeStruckture.push(Maze.WALL);
}
setCell(new Vec(Math.round(Math.random() * (size.x - 1)), Math.round(Math.random() * (size.y - 1))), Maze.INTERSECTION);
}
getCell(pos) {
return (this.mazeStruckture[pos.x + pos.y * this.size.x]);
// return PATH / WALL;
}
setCell(pos, value) {
this.mazeStruckture[pos.x + pos.y * this.size.x] = value;
}
}
Maze.WALL = 0;
Maze.WAY = 1;
Maze.INTERSECTION = 2;
testMaze = new Maze(new Vec(5, 5));
console.log(testMaze.getCell(0, 0));
module.exports = Maze;