Add setup to grid

This commit is contained in:
Topher Lamey
2021-02-27 22:33:03 -07:00
parent d0c396b73d
commit 37681a40b6

View File

@@ -45,15 +45,13 @@ public class Amazing {
Grid grid = new Grid(length, width); Grid grid = new Grid(length, width);
int enterCol = random(0, width);
int col = enterCol;
int row = 0; int row = 0;
int count = 1;
int totalWalls = width * length + 1; int totalWalls = width * length + 1;
// set up entrance int enterCol = grid.setup();
grid.cells[row][col].count = count; int col = enterCol;
count++; int count = 2;
while (count != totalWalls) { while (count != totalWalls) {
ArrayList<Direction> possibleDirs = getPossibleDirs(grid, new Cell(row, col)); ArrayList<Direction> possibleDirs = getPossibleDirs(grid, new Cell(row, col));
@@ -192,19 +190,28 @@ public class Amazing {
int lastCol; int lastCol;
int lastRow; int lastRow;
public Grid(int length, int width) { int width;
lastCol = width - 1;
lastRow = length - 1;
cells = new Cell[length][width]; public Grid(int length, int width) {
this.lastCol = width - 1;
this.lastRow = length - 1;
this.width = width;
this.cells = new Cell[length][width];
for (int i=0; i < length; i++) { for (int i=0; i < length; i++) {
cells[i] = new Cell[width]; this.cells[i] = new Cell[width];
for (int j = 0; j < width; j++) { for (int j = 0; j < width; j++) {
cells[i][j] = new Cell(i, j); this.cells[i][j] = new Cell(i, j);
} }
} }
} }
public int setup() {
int enterCol = random(0, this.width);
cells[0][enterCol].count = 1;
return enterCol;
}
public boolean isPrevColSet(Cell cell) { public boolean isPrevColSet(Cell cell) {
return 0 != cells[cell.row][cell.col - 1].count; return 0 != cells[cell.row][cell.col - 1].count;
} }