Maze generation working with new Maze object.

This commit is contained in:
2020-05-19 09:09:21 -05:00
parent 2fbcc0b345
commit eece3deffb
3 changed files with 16 additions and 52 deletions
+7 -39
View File
@@ -14,49 +14,17 @@ function setup() {
canvas.parent('sketch-holder');
maze = new Maze(width, height, cellWidth);
frameRate(60);
rows = floor(width / cellWidth);
columns = floor(height / cellWidth);
for (let y = 0; y < rows; y++) {
for (var x = 0; x < columns; x++) {
grid.push(new Cell(x, y, cellWidth));
}
}
//currentCell = grid[0];
grid[0].visited = true;
grid[0].selected = true;
cellStack.push(grid[0]);
}
function draw() {
background(220);
for (var i = 0; i < grid.length; i++) {
grid[i].show();
}
maze.updateMazeDisplay();
if(cellStack.length > 0){
//Build the maze
let currentCell = cellStack.pop();
//currentCell.visited = true;
let nextCell = getNeighbors(currentCell);
if(nextCell){
cellStack.push(currentCell);
currentCell.Selected = false;
currentCell.visited = true;
nextCell.visited = true;
nextCell.selected = true;
removeWalls(currentCell, nextCell);
cellStack.push(nextCell);
} else cellStack.pop();
currentCell.selected = false;
if(maze.workingStack.length > 0){
maze.buildNextCell();
}
else if (cellStack.length == 0 && frontier.length == 0 && explored.length == 0){
/*else if (cellStack.length == 0 && frontier.length == 0 && explored.length == 0){
for (var i = 0; i < grid.length; i++) {
grid[i].visited = false;
}
@@ -91,9 +59,9 @@ function draw() {
if(currentNode.x == 9 && currentNode.y == 9)
//currentNode.end = true;
frontier = [];
}
}*/
else{
tmp = explored.pop();
/*tmp = explored.pop();
while (tmp.parent != undefined) {
tmp.finalPath = true;
@@ -103,7 +71,7 @@ function draw() {
for (var i = 0; i < grid.length; i++) {
grid[i].show();
}
}*/
print("Maze search done");