0
基本的に私がやろうとしているのは、迷路内の各斑点を乱数に基づいて特定の列挙型に設定することです。つまり、迷路に10個の壁をランダムに配置します。壁の列挙型。これは私がこれまでに持っていたコードであり、どのように動作させるかを理解することはできません。列挙型がint配列に設定されている
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);
同じセルを複数回取り出すことができます。その結果、壁が10個未満になります。これを修正する方法の1つは、次のようになります。 'set(random).MultiInt(maze.length)] [randomMaze.nextInt(maze.length)] .getType()。equals(WALL)) 。 –