Features:
1. Customize the maze size
2. randomly generate a maze using the depth traversal of the graph
3. Draw a custom maze with the mouse
4. One-step solution to the maze
5. One-click solution to the maze
6. Sound Effects
Download the complete project:
Http://download.csdn.net/detail/wxg694175346/5179044
Program:
I. System Development Platform
Maze mouse: uses the stack to find the path solution of the maze.
Programming Language: Java
Development tools: Eclipse
Operating System: Windows
Ii. System Planning
2.1 task statement
The application of the Maze mouse is mainly used
Solve the Problem of path finding in the maze.
2.2 task objectives
Solve the Maze problem: entry a enters and Exit B
Randomly design and solve a maze
Customize and solve a maze.
Iii. system definition
Iv. Requirement Analysis
4.1 Data Structure requirements
The data structure mainly involves three parts:
1. vertex Data Object: contains four 1/0 integer data to indicate the connectivity between the four directions of the vertex, and there is no connection between the data.
2. Map of the Maze: the path of the Maze needs to be stored. The size is fixed. The elements in the Maze are not correlated and do not affect each other. There is no sequential order. The data type in the group is encapsulated vertex object class.
3. path in the Maze solution: the path to be stored. The elements are encapsulated vertex objects. Elements must be arranged in order, first-in-first-out mode, and the data size is unaffected.
4.2 operation requirements
1. Random Mode
2. In the custom Mode
V. Implementation idea (two parts: random generation of solvable maze and custom maze)
1. randomly generate a solution to the maze:
First, the maze consists of N x n square points, each of which has a property value of a wall that controls the upper, lower, and left directions, and is used to push down the wall to build a path between two points. If there is a path between the two points, that is, to make the left square push down the right wall, the right square pushes down the left wall, this path is formed, and the points that constitute the maze are saved by setting the Point property value.
The depth-first traversal principle is used to traverse random depth of any accessible point from the starting point (0, 0, until all vertices are traversed until now (all vertices are traversed here to make the maze look more harmonious and beautiful, and increase the complexity of the maze ), the path of deep traversal is the path that the maze can walk. When the maze is solved, the path can only be sought on the specified path, which indirectly forms the maze.
Because of the deep traversal feature of the graph, the starting point (0, 0) can reach any point in the graph. Here, the end point is set to the last point of the matrix, ensuring that there is a path from the starting point to the end point, and the path is unique. Form all vertices that constitute the maze into a variable array arraylist for use in the maze.
When the maze is solved, the right direction is selected first, then down, and then up to the left, and a method is provided to determine whether a path exists between the two points in the direction, if the next reachable point is found, the point is added to the stack. If no point is found, a point is taken from the stack to form a loop.
2. Custom maze
First, generate M * n squares based on the input, and click events with the mouse to generate obstacles at the clicked squares, thus generating a maze.
When solving the maze, based on the above solution to the maze, add a judgment without a path (that is, the judgment that cannot reach the end point), that is, the stack is already empty, but you still need to retrieve points from it, it indicates that no point can be reached in this maze. In this case, it indicates that there is no path in the Maze and a prompt is given to the user to solve the maze.
Vi. Data Structure Design
First, we use dynamic arrays to store all the mazepoint classes in the Maze. In the process of randomly generating and customizing the maze, we construct the maze by setting these maze points.
The key to data structure design is embodied in the solution of the maze. Here I use the stack idea to explain the point pushed into the stack during the maze. When the next point cannot be found at one point, the top-level vertex in the stack is retrieved, and the vertex is set as the current vertex to find the reachable vertex. This process is performed in sequence until the vertex reaches the end point or no vertex in the stack can be retrieved.
It is assumed that the searched points are uniquely identified in the process of solving the maze. When a loop is formed and then the reachable points are searched, these uniquely identified points will not be reached twice, this ensures that the maze will not have an endless loop.