0

基本上我要做的是根据随机数将迷宫中的每个点设置为特定的枚举类型,即我在迷宫上随机放置 10 个墙,这 10 个空间将是墙枚举类型。这是我到目前为止的代码,我不知道如何让它工作。

public enum CellType {
   CHEESE, OPEN, WALL, VISITED, MOUSE
}

public class Cell {

private Color color;
private ImageIcon image;
CellType type;


public Color getColor() {
    return color;
}
public void setColor(Color color) {
    this.color = color;
}
public ImageIcon getImage() {
    return image;
}
public void setImage(ImageIcon image) {
    this.image = image;
}
public CellType getType() {
    return type;
}
public void setType(CellType type) {
    this.type = type;
}

}

maze = new int[row][col];       
Random randomMaze = new Random();
for (int ran = 0; ran <= numWalls ; ran++)
    maze[randomMaze.nextInt(maze.length)][randomMaze.nextInt(maze.length)].setType(WALL);
4

1 回答 1

2

maze应该是 s 的二维数组Cell,而不是 s 的二维数组int

于 2012-04-10T01:39:42.590 回答