我的目标是生成一个由 Cell 对象的 2D 数组组成的迷宫。下面是单元格和迷宫的代码。使用调试器我可以看到布尔值正在改变值,并且生成按预期进行,但是当它打印出来时,没有路径。所有的墙都还在原地,我似乎无法弄清楚断开的位置,如果有的话?这是 Cell 类:public class Cell { //coordinates private int x; private int y; //cell status private boolean visited; //cell walls status private boolean northWall; private boolean southWall; private boolean eastWall; private boolean westWall; public Cell(int x, int y) { this.x = x; this.y = y; visited = false; northWall= true; southWall= true; eastWall = true; westWall = true; } public int getX() { return x; } public int getY() { return y; } public boolean isVisited() { return visited; } public void setVisited(boolean visited) { this.visited = visited; } public boolean isNorthWall() { return northWall; } public void setNorthWall(boolean northWall) { this.northWall = northWall; } public boolean isSouthWall() { return southWall; } public void setSouthWall(boolean southWall) { this.southWall = southWall; } public boolean isEastWall() { return eastWall; } public void setEastWall(boolean eastWall) { this.eastWall = eastWall; } public boolean isWestWall() { return westWall; } public void setWestWall(boolean westWall) { this.westWall = westWall; }
2 回答

汪汪一只猫
TA贡献1898条经验 获得超8个赞
你不是在打印你的迷宫。
在该printMaze()方法中,您正确地循环了迷宫,但不是打印出迷宫单元格,而是在每次迭代时创建一个新的(空白)单元格。
public void printMaze() {
for (int i = 0; i < height; i++) {
/* ... */
for (int j = 0; j < width; j++) {
Cell current = new Cell(i, j); // <- HERE
/* ... */
}
/* ... */
}
/* ... */
}
该行应该是:
Cell current = maze[i][j];
添加回答
举报
0/150
提交
取消