Answered step by step
Verified Expert Solution
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 Maze
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:
START,BA
BCK
CDE
VNA
EXIT,AA
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
Draws a maze on the panel You are going to decide how to label the nodes
Walk through the maze and find path from start to exit. You need to show an animation
of how your program finds a path from start to exit.
Highlight the path from start to exit and display the path on the panel.
nodes names of the path are displayed in order from Start to Exit
make sure your program works for both txt files.
GUI is provided.
A jar file is created.
And here is my code
package Question;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
@author xhu
public class BinaryMaze
@param args the command line arguments
public static void mainString args
JFrame frame new JFrameMaze;
frame.setDefaultCloseOperationJFrameEXITONCLOSE;
frame.setSize;
frame.addnew Panel;
frame.setVisibletrue;
package Question;
import java.io;
import java.nio.file.;
import java.util.;
@author xhu
public class FileManager
private String lineData;
public FileManagerString fileName
try
List lines Files.readAllLinesPathsgetfileName;
lineData lines.toArraynew String;
catch IOException e
eprintStackTrace;
public String getLineData
return lineData;
package Question;
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
;
public MazeString fileName
this.nodes new HashMap;
this.visited new HashSet;
FileManager fileManager new FileManagerfileName;
String lines fileManager.getLineData;
String header linessplit;
this.numberOfLinkers Integer.parseIntheader;
this.numberOfColumns Integer.parseIntheader;
this.numberOfRows Integer.parseIntheader;
for int i ; i lines.length; i
String nodeData linesisplit;
String nodeName nodeData;
int x Integer.parseIntnodeData;
int y Integer.parseIntnodeData;
Node node new NodenodeName x y;
for int j ; j nodeData.length; j
String nextNodeName nodeDataj;
if nextNodeName.equalsA
node.addNextNodeNamenextNodeName;
nodes.putnodeName node;
public boolean isValidLocationint row, int col
return row && row numberOfRows && col && col numberOfColumns;
public boolean isWallint The problem is that my does not link with my exist also the letter should be on top of the
vertices and also that it should be displaying of my text file
This is what it suppose to look like
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started