枚举类型设置为int数组

时间:2012-04-10 01:35:25

标签: java arrays enums int

基本上我要做的是将迷宫中的每个点设置为基于随机数的特定枚举类型,即我在迷宫上随机放置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);

1 个答案:

答案 0 :(得分:2)

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

相关问题