Maze generation working with new Maze object.
This commit is contained in:
+8
-9
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user