-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMaze.java
91 lines (72 loc) · 2.4 KB
/
Maze.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package visualization;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
public class Maze extends JPanel {
public static void main(String[] args) {
JFrame mainFrame = new JFrame();
mainFrame.setTitle("visualization.Maze v0.1");
mainFrame.setSize(500,500);
Maze m = new Maze();
//m.setBackground(new Color(150,150,150));
mainFrame.add(m);
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainFrame.setVisible(true);
}
public MazeCell[][] mazeButtons;
int mazeSize = 10;
public Maze(){
this.setLayout(new BorderLayout());
JButton solveButton = new JButton();
solveButton.setText("Solve visualization.Maze !");
solveButton.addActionListener((ActionEvent e) -> solve());
this.add(solveButton,BorderLayout.SOUTH);
JPanel mazeCellHost = new JPanel();
//init cells
mazeCellHost.setLayout(new GridLayout(10,10));
mazeButtons = new MazeCell[mazeSize][mazeSize];
for (int i = 0; i < mazeSize ; i++) {
for (int j = 0; j < mazeSize; j++) {
MazeCell m = new MazeCell(i,j);
//b.addActionListener(new MazeButtonActionListener(i,j));
mazeButtons[i][j] = m;
mazeCellHost.add(m);
}
}
this.add(mazeCellHost);
}
public void solve(){
int sx = -1;
int sy = -1;
//get source node
for (int i = 0; i < mazeSize; i++) {
for (int j = 0; j < mazeSize; j++) {
if(mazeButtons[i][j].color == 2){
sx = i;
sy = j;
}
}
}
for (int i = 0; i < mazeSize ; i++) {
for (int j = 0; j < mazeSize; j++) {
visited[i][j] = false;
}
}
}
boolean[][] visited;
public void addAdjNodes(int x, int y, GraphNode n){
}
/*class MazeButtonActionListener implements ActionListener {
private int x;
private int y;
public MazeButtonActionListener(int x , int y){
this.x = x;
this.y = y;
}
@Override
public void actionPerformed(ActionEvent e) {
mazeButtons[x][y].setText("0");
System.out.println("algorithm.Action Recorded : " + x + " , "+ y);
}
}*/
}