Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 3 ) Maze ( 3 0 % ) You are going to design a maze program. It loads a maze from a maze text

Question 3) Maze (30%)
You are going to design a maze program. It loads a maze from a maze text file then program walks
through the maze and finds the path from starting vertex to the exiting vertex.
Maze text file format:
Number of edges, Number of columns, number of rows (Header of maze)
Vertexs name, x position, y position, next linked vertexs name, next linked vertexs name
...
Vertexs name, x position, y position, next linked vertexs name, next linked vertexs name
Example:
22,7,6
START,0,2,B,A
B,1,2,C,K
C,1,3,D,E
...
V,4,1,N,A
EXIT,6,2,A,A
A is the same as null. It means not next linked vertex on this path (this path has no exit).
W links to exit.
Your task is to write a program. The program does:
Loads a maze txt files (there are two txt files)(3%)
Draws a maze on the panel (You are going to decide how to label the nodes).(3%)
Walk through the maze and find path from start to exit. (5%) You need to show an animation
of how your program finds a path from start to exit. (3%)
Highlight the path from start to exit and display the path on the panel. (3%)
nodes names of the path are displayed in order from Start to Exit.(5%)
make sure your program works for both txt files. (7%)
GUI is provided. (1%)
A jar file is created.
And here is my code
package Question_3;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
*
* @author xhu
*/
public class BinaryMaze {
/**
* @param args the command line arguments
*/
public static void main(String[] args){
JFrame frame = new JFrame("Maze");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,600);
frame.add(new Panel());
frame.setVisible(true);
}
}
package Question_3;
import java.io.*;
import java.nio.file.*;
import java.util.*;
/**
*
* @author xhu
*/
public class FileManager {
private String[] lineData;
public FileManager(String fileName){
try {
List lines = Files.readAllLines(Paths.get(fileName));
lineData = lines.toArray(new String[0]);
} catch (IOException e){
e.printStackTrace();
}
}
public String[] getLineData(){
return lineData;
}
}
package Question_3;
import java.util.*;
/**
*
* @author xhu
*/
public class Maze {
private int numberOfLinkers;
private int numberOfColumns;
private int numberOfRows;
private Map nodes;
private Set visited;
private static final int[][] DIRECTIONS ={
{0,1},{1,0},{0,-1},{-1,0}
};
public Maze(String fileName){
this.nodes = new HashMap>();
this.visited = new HashSet>();
FileManager fileManager = new FileManager(fileName);
String[] lines = fileManager.getLineData();
String[] header = lines[0].split(",");
this.numberOfLinkers = Integer.parseInt(header[0]);
this.numberOfColumns = Integer.parseInt(header[1]);
this.numberOfRows = Integer.parseInt(header[2]);
for (int i =1; i lines.length; i++){
String[] nodeData = lines[i].split(",");
String nodeName = nodeData[0];
int x = Integer.parseInt(nodeData[1]);
int y = Integer.parseInt(nodeData[2]);
Node node = new Node(nodeName, x, y);
for (int j =3; j nodeData.length; j++){
String nextNodeName = nodeData[j];
if (!nextNodeName.equals("A")){
node.addNextNodeName(nextNodeName);
}
}
nodes.put(nodeName, node);
}
}
public boolean isValidLocation(int row, int col){
return row >=0 && row numberOfRows && col >=0 && col numberOfColumns;
}
public boolean isWall(int The problem is that my U does not link with my exist also the letter should be on top of the
vertices and also that it should be displaying 2 of my text file
This is what it suppose to look like
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data Concepts, Theories, And Applications

Authors: Shui Yu, Song Guo

1st Edition

3319277634, 9783319277639

More Books

Students also viewed these Databases questions