Related questions
Concept explainers
Change the following code so that there is always at least one way to get from the left corner to the top right, but the labyrinth is still randomized.
The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. Take care that the player and the dragon cannot start off on walls. Also the dragon starts off from a randomly chosen position
public class Labyrinth {
private final int size;
private final Cell[][] grid;
public Labyrinth(int size) {
this.size = size;
this.grid = new Cell[size][size];
generateLabyrinth();
}
private void generateLabyrinth() {
Random rand = new Random();
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
// Randomly create walls and paths
grid[i][j] = new Cell(rand.nextBoolean());
}
}
// Ensure start and end are open paths
grid[9][0].setWall(false);
grid[size - 1][size - 1].setWall(false);
}
}
Step by stepSolved in 2 steps
- Text book imageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTText book imageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Text book imageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- Text book imageC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrText book imageProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageText book imageOperations Research : Applications and AlgorithmsComputer ScienceISBN:9780534380588Author:Wayne L. WinstonPublisher:Brooks Cole