@@ -152,8 +152,6 @@ public Game(JFrame frame) {
152152 setTimerSolving ();
153153 }
154154
155-
156-
157155 private void resetButton () {
158156 JButton result = new JButton ("Reset" );
159157 result .addActionListener (new ActionListener () {
@@ -184,7 +182,6 @@ public void actionPerformed(ActionEvent e) {
184182 setTimerMageCreation ();
185183 setTimerSolving ();
186184 repaint ();
187-
188185 }
189186 });
190187 buttonPanel .add (result );
@@ -257,25 +254,33 @@ public void actionPerformed(ActionEvent e) {
257254 if (startTile == null ) {
258255 System .out .println ("Please select start location" );
259256 }
257+
260258 if (goalTile == null ) {
261259 System .out .println ("Please select goal location" );
262260 }
263261
264262 if (startTile != null && goalTile != null ) {
263+ resetCameFrom (tiles ); // useful if the user wants to search for the second time or more
265264 ant = new Ant (startTile , goalTile , TILE_SIZE , tiles );
266265 startClicked = true ;
267266 startTimeBeforeAnimation = System .currentTimeMillis ();
268267 ant .search ();
269268 delayPaint ();
270269 }
271-
272-
273270 }
274271 });
275272 buttonPanel .add (result );
276273 return result ;
277274 }
278275
276+ private void resetCameFrom (Tile [][] tiles ) {
277+ for (int i = 0 ; i < tiles .length ; i ++) {
278+ for (int j = 0 ; j < tiles [i ].length ; j ++) {
279+ tiles [i ][j ].resetCameFrom ();
280+ }
281+ }
282+ }
283+
279284 private void selectGoalLocation () {
280285 JButton result = new JButton ("Goal Location" );
281286 result .addActionListener (new ActionListener () {
@@ -342,6 +347,19 @@ private void handleStartLocationSelection(Tile clickedTile) {
342347 if (startTile != null ){
343348 startTile .resetStart ();
344349 }
350+
351+ startClicked = false ;
352+ startMovingAnt = false ;
353+ noPath = false ;
354+ ant = null ;
355+ tobeDrawn = new LinkedList <Tile >();
356+
357+ obstacleCount = 0 ;
358+ swamplandCount = 0 ;
359+ grasslandCount = 0 ;
360+ openTerrainCount = 0 ;
361+
362+
345363 // Set the clicked tile as the start location
346364 clickedTile .setStart ();
347365 startTile = clickedTile ;
0 commit comments