EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
100%

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);
}

}

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Operations Research : Applications and Algorithms
Computer Science
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Brooks Cole