Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 枚举类型设置为整数数组_Java_Arrays_Enums_Int - Fatal编程技术网

Java 枚举类型设置为整数数组

Java 枚举类型设置为整数数组,java,arrays,enums,int,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 getC

基本上,我想做的是根据随机数将迷宫中的每个点设置为特定的枚举类型,即我在迷宫上随机放置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=newint[row][col];
随机迷宫=新随机();

对于(int-ran=0;ran
maze
应该是一个由
单元格组成的二维数组,而不是一个由
int
s组成的二维数组。

可以多次拾取同一单元格,这将导致少于10堵墙。解决此问题的一种方法是:
如果(maze[randomMaze.nextInt(maze.length)][randomMaze.nextInt(maze.length)].getType().equals(WALL))在设置之前运行--;
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);