diff --git a/gen-maze.js b/gen-maze.js
index a79f5d4..bee5ee9 100644
--- a/gen-maze.js
+++ b/gen-maze.js
@@ -6,7 +6,6 @@ class Maze{
this.height = mazeHeight;
this.cellWidth = cellWidth;
this.workingStack = [];
- this.currentCell = {};
this.grid = [];
for (let y = 0; y < this.rows; y++) {
@@ -28,12 +27,12 @@ class Maze{
buildNextCell(){
//Build the maze
- this.currentCell = this.workingStack.pop();
+ let currentCell = this.workingStack.pop();
//currentCell.visited = true;
- let nextCell = getNeighbors(this.currentCell);
+ let nextCell = this.getNeighbors(currentCell);
if(nextCell){
- this.workingStack.push(this.currentCell);
+ this.workingStack.push(currentCell);
currentCell.Selected = false;
currentCell.visited = true;
nextCell.visited = true;
@@ -44,7 +43,7 @@ class Maze{
else
this.workingStack.pop();
- this.currentCell.selected = false;
+ currentCell.selected = false;
}
get mazeGenDone() {
@@ -54,10 +53,10 @@ class Maze{
getNeighbors(cell){
var visited = [];
- var top = this.grid[index(cell.x, cell.y - 1)];
- var left = this.grid[index(cell.x - 1, cell.y)];
- var bottom = this.grid[index(cell.x, cell.y + 1)];
- var right = this.grid[index(cell.x + 1, cell.y)];
+ var top = this.grid[this.index(cell.x, cell.y - 1)];
+ var left = this.grid[this.index(cell.x - 1, cell.y)];
+ var bottom = this.grid[this.index(cell.x, cell.y + 1)];
+ var right = this.grid[this.index(cell.x + 1, cell.y)];
if (top && !top.visited) {
visited.push(top);
diff --git a/index.html b/index.html
index 333da43..1acca4e 100644
--- a/index.html
+++ b/index.html
@@ -22,11 +22,8 @@
clear: both;
}
-
+
diff --git a/sketch.js b/sketch.js
index 7c94cea..ebf781d 100644
--- a/sketch.js
+++ b/sketch.js
@@ -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");