//Randomly destroy a wall to make a path private void DestroyWall(int row, int column) { bool wallDestroyed = false; while (!wallDestroyed) { int direction = NumGen.GetNextNumber(); Debug.Log("Direction" + direction); if (direction == 1 && row > 0 && mazeCells [row - 1, column].visited) { DestroyWallIfItExists(mazeCells [row, column].nWall); DestroyWallIfItExists(mazeCells [row - 1, column].sWall); wallDestroyed = true; } else if (direction == 2 && row < (mazeRows - 2) && mazeCells [row + 1, column].visited) { DestroyWallIfItExists(mazeCells [row, column].sWall); DestroyWallIfItExists(mazeCells [row + 1, column].nWall); wallDestroyed = true; } else if (direction == 3 && column > 0 && mazeCells [row, column - 1].visited) { DestroyWallIfItExists(mazeCells [row, column].wWall); DestroyWallIfItExists(mazeCells [row, column - 1].eWall); wallDestroyed = true; } else if (direction == 4 && column < (mazeColumns - 2) && mazeCells [row, column + 1].visited) { DestroyWallIfItExists(mazeCells [row, column].eWall); DestroyWallIfItExists(mazeCells[row, column + 1].wWall); } } }
//Kill Part of our Algorithim private void Kill() { while (AvailbleRoute(currentRow, currentCol)) { int direction = NumGen.GetNextNumber(); Debug.Log("Direction for KillMethod " + direction); if (direction == 1 && CellIsAvailable(currentRow - 1, currentCol)) { // North Wall DestroyWallIfItExists(mazeCells [currentRow, currentCol].nWall); DestroyWallIfItExists(mazeCells [currentRow - 1, currentCol].sWall); currentRow--; } else if (direction == 2 && CellIsAvailable(currentRow + 1, currentCol)) { // South Wall DestroyWallIfItExists(mazeCells [currentRow, currentCol].sWall); DestroyWallIfItExists(mazeCells [currentRow + 1, currentCol].nWall); currentRow++; } else if (direction == 3 && CellIsAvailable(currentRow, currentCol + 1)) { // east wall DestroyWallIfItExists(mazeCells [currentRow, currentCol].eWall); DestroyWallIfItExists(mazeCells [currentRow, currentCol + 1].wWall); currentCol++; } else if (direction == 4 && CellIsAvailable(currentRow, currentCol - 1)) { // west wall DestroyWallIfItExists(mazeCells [currentRow, currentCol].wWall); DestroyWallIfItExists(mazeCells [currentRow, currentCol - 1].eWall); currentCol--; } mazeCells [currentRow, currentCol].visited = true; } }