Skip to content

Commit 26a39c8

Browse files
committed
refactoring CoolMaze
1 parent 5f5c90b commit 26a39c8

1 file changed

Lines changed: 39 additions & 33 deletions

File tree

  • src/main/java/org/teachingextensions/logo/utils/MazeUtils

src/main/java/org/teachingextensions/logo/utils/MazeUtils/CoolMaze.java

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,39 @@
44

55
public class CoolMaze
66
{
7-
private int N;
8-
private boolean[][] north;
9-
private boolean[][] east;
10-
private boolean[][] south;
11-
private boolean[][] west;
12-
private boolean[][] visited;
13-
private boolean done = false;
7+
public static void main(String[] args)
8+
{
9+
int mazeComplexity = 10;
10+
CoolMaze maze = new CoolMaze(mazeComplexity);
11+
StdDraw.show(0);
12+
maze.drawWallsAndStartAndEndPoints();
13+
maze.solveThisMaze();
14+
}
1415
public CoolMaze(int N)
1516
{
1617
setMazeScale(N);
1718
createMazeStructure();
1819
generateStartLocation(1, 1);
1920
}
21+
public void solveThisMaze()
22+
{
23+
int startingX = 1;
24+
int startingY = 1;
25+
for (int x = startingX; x <= N; x++)
26+
for (int y = startingY; y <= N; y++)
27+
visited[x][y] = false;
28+
done = false;
29+
solve(startingX, startingY);
30+
}
31+
public void drawWallsAndStartAndEndPoints()
32+
{
33+
Color colorOfStartAndEndPoints = StdDraw.RED;
34+
StdDraw.setPenColor(colorOfStartAndEndPoints);
35+
createAndSizeStartPoint();
36+
createAndSizeEndPoint();
37+
drawAndColorMazeWalls();
38+
StdDraw.show(1000);
39+
}
2040
private void setMazeScale(int N)
2141
{
2242
this.N = N;
@@ -130,23 +150,6 @@ private void drawAndSizeSolvePath(int x, int y)
130150
{
131151
StdDraw.filledCircle(x + 0.5, y + 0.5, 0.25);
132152
}
133-
public void solveThisMaze()
134-
{
135-
for (int x = 1; x <= N; x++)
136-
for (int y = 1; y <= N; y++)
137-
visited[x][y] = false;
138-
done = false;
139-
solve(1, 1);
140-
}
141-
public void drawWallsAndStartAndEndPoints()
142-
{
143-
Color colorOfStartAndEndPoints = StdDraw.RED;
144-
StdDraw.setPenColor(colorOfStartAndEndPoints);
145-
createAndSizeStartPoint();
146-
createAndSizeEndPoint();
147-
drawMazeWalls();
148-
StdDraw.show(1000);
149-
}
150153
private void createAndSizeEndPoint()
151154
{
152155
StdDraw.filledCircle(N / 2.0 + 0.5, N / 2.0 + 0.5, 0.375);
@@ -155,10 +158,14 @@ private void createAndSizeStartPoint()
155158
{
156159
StdDraw.filledCircle(1.5, 1.5, 0.375);
157160
}
158-
private void drawMazeWalls()
161+
private void drawAndColorMazeWalls()
159162
{
160163
Color colorOfMazeWalls = StdDraw.BLACK;
161164
StdDraw.setPenColor(colorOfMazeWalls);
165+
drawMazeWalls();
166+
}
167+
private void drawMazeWalls()
168+
{
162169
for (int x = 1; x <= N; x++)
163170
{
164171
for (int y = 1; y <= N; y++)
@@ -174,12 +181,11 @@ private void drawMazeWalls()
174181
}
175182
}
176183
}
177-
public static void main(String[] args)
178-
{
179-
int mazeComplexityDepth = 10;
180-
CoolMaze maze = new CoolMaze(mazeComplexityDepth);
181-
StdDraw.show(0);
182-
maze.drawWallsAndStartAndEndPoints();
183-
maze.solveThisMaze();
184-
}
184+
private int N;
185+
private boolean[][] north;
186+
private boolean[][] east;
187+
private boolean[][] south;
188+
private boolean[][] west;
189+
private boolean[][] visited;
190+
private boolean done = false;
185191
}

0 commit comments

Comments
 (0)