11package org .teachingextensions .logo .utils .MazeUtils ;
22
3+ import java .awt .Color ;
4+
35public class CoolMaze
46{
57 private int N ;
@@ -10,12 +12,16 @@ public class CoolMaze
1012 private boolean [][] visited ;
1113 private boolean done = false ;
1214 public CoolMaze (int N )
15+ {
16+ setMazeScale (N );
17+ createMazeStructure ();
18+ generateStartLocation (1 , 1 );
19+ }
20+ private void setMazeScale (int N )
1321 {
1422 this .N = N ;
1523 StdDraw .setXscale (0 , N + 2 );
1624 StdDraw .setYscale (0 , N + 2 );
17- createMazeStructure ();
18- generateStartLocation (1 , 1 );
1925 }
2026 private void createMazeStructure ()
2127 {
@@ -91,9 +97,7 @@ private void solve(int x, int y)
9197 if (done || visited [x ][y ])
9298 return ;
9399 visited [x ][y ] = true ;
94- StdDraw .setPenColor (StdDraw .BLUE );
95- StdDraw .filledCircle (x + 0.5 , y + 0.5 , 0.25 );
96- StdDraw .show (30 );
100+ renderCorrectSolveDots (x , y );
97101 if (x == N / 2 && y == N / 2 )
98102 done = true ;
99103 if (!north [x ][y ])
@@ -106,10 +110,26 @@ private void solve(int x, int y)
106110 solve (x - 1 , y );
107111 if (done )
108112 return ;
109- StdDraw .setPenColor (StdDraw .GRAY );
110- StdDraw .filledCircle (x + 0.5 , y + 0.5 , 0.25 );
113+ renderIncorrectSolveDots (x , y );
114+ }
115+ private void renderCorrectSolveDots (int x , int y )
116+ {
117+ Color colorOfCorrectSolvePath = StdDraw .BLUE ;
118+ StdDraw .setPenColor (colorOfCorrectSolvePath );
119+ drawAndSizeSolvePath (x , y );
120+ StdDraw .show (30 );
121+ }
122+ private void renderIncorrectSolveDots (int x , int y )
123+ {
124+ Color colorOfIncorrectSolvePath = StdDraw .GRAY ;
125+ StdDraw .setPenColor (colorOfIncorrectSolvePath );
126+ drawAndSizeSolvePath (x , y );
111127 StdDraw .show (30 );
112128 }
129+ private void drawAndSizeSolvePath (int x , int y )
130+ {
131+ StdDraw .filledCircle (x + 0.5 , y + 0.5 , 0.25 );
132+ }
113133 public void solveThisMaze ()
114134 {
115135 for (int x = 1 ; x <= N ; x ++)
@@ -118,12 +138,27 @@ public void solveThisMaze()
118138 done = false ;
119139 solve (1 , 1 );
120140 }
121- public void drawStartAndEndPoints ()
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+ }
150+ private void createAndSizeEndPoint ()
122151 {
123- StdDraw .setPenColor (StdDraw .RED );
124152 StdDraw .filledCircle (N / 2.0 + 0.5 , N / 2.0 + 0.5 , 0.375 );
153+ }
154+ private void createAndSizeStartPoint ()
155+ {
125156 StdDraw .filledCircle (1.5 , 1.5 , 0.375 );
126- StdDraw .setPenColor (StdDraw .BLACK );
157+ }
158+ private void drawMazeWalls ()
159+ {
160+ Color colorOfMazeWalls = StdDraw .BLACK ;
161+ StdDraw .setPenColor (colorOfMazeWalls );
127162 for (int x = 1 ; x <= N ; x ++)
128163 {
129164 for (int y = 1 ; y <= N ; y ++)
@@ -138,14 +173,13 @@ public void drawStartAndEndPoints()
138173 StdDraw .line (x + 1 , y , x + 1 , y + 1 );
139174 }
140175 }
141- StdDraw .show (1000 );
142176 }
143177 public static void main (String [] args )
144178 {
145179 int mazeComplexityDepth = 10 ;
146180 CoolMaze maze = new CoolMaze (mazeComplexityDepth );
147181 StdDraw .show (0 );
148- maze .drawStartAndEndPoints ();
182+ maze .drawWallsAndStartAndEndPoints ();
149183 maze .solveThisMaze ();
150184 }
151185}
0 commit comments