0

basically what i am trying to do is to set each spot in my maze to a specific enumerated type based on a random number i.e i randomly place 10 walls on the maze and those 10 spaces would be wall enum types. This is the code i have so far, and i cant figure out how to get it to work.

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
  • It's possible for the same cell to be picked more than once, which would result in fewer than 10 walls. One way to fix this would be: if (maze[randomMaze.nextInt(maze.length)][randomMaze.nextInt(maze.length)].getType().equals(WALL)) ran--; before the set. Commented Apr 10, 2012 at 1:42

1 Answer 1

2

maze should be a 2D array of Cells, not a 2D array of ints.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.