我还在为我的迷宫游戏制作我的Cell课程.在另一个线程的帮助之后,有人建议我使用EnumMap作为我的墙/邻居,这到目前为止工作得很好.
这是我到目前为止:
enum Dir {
NORTH, SOUTH, EAST, WEST
}
class Cell {
public Map<Dir, Cell> neighbors = Collections
.synchronizedMap(new EnumMap<Dir, Cell>(Dir.class));
public Map<Dir, Boolean> walls = Collections
.synchronizedMap(new EnumMap<Dir, Boolean>(Dir.class));
public boolean Visited;
public Cell() {
Visited = false;
for (Dir direction : Dir.values()) {
walls.put(direction, true);
}
}
// Randomly select an unvisited neighbor and tear down the walls
// between this cell and that neighbor.
public Cell removeRandomWall() {
List<Dir> unvisitedDirections = new ArrayList<Dir>();
for (Dir direction …Run Code Online (Sandbox Code Playgroud)