@@ -33,7 +33,7 @@ The robot character (an ant) should find its way from the start point (home) to
3333import java .awt .event .MouseListener ;
3434import java .io .File ;
3535import java .io .IOException ;
36- import java .util .ArrayList ;
36+ import java .util .LinkedList ;
3737import javax .swing .Timer ;
3838import javax .imageio .ImageIO ;
3939import javax .swing .JButton ;
@@ -47,7 +47,7 @@ public class Game extends JPanel implements MouseListener {
4747
4848 private Ant ant ;
4949 private Tile [][] tiles ;
50- private ArrayList <Tile > tobeDrawn ;
50+ private LinkedList <Tile > tobeDrawn ;
5151 private boolean startMovingAnt ;
5252
5353 private Tile startTile ;
@@ -91,7 +91,7 @@ public Game() {
9191 startTile = null ;
9292 goalTile = null ;
9393 startMovingAnt = false ;
94- tobeDrawn = new ArrayList <Tile >();
94+ tobeDrawn = new LinkedList <Tile >();
9595 }
9696
9797 private void loadFoodImg () {
@@ -335,7 +335,7 @@ private Tile fetchTile(int mouseX, int mouseY) {
335335 public void delayPaint () {
336336 int delay = 100 ; // 1 second delay
337337 Timer timer = new Timer (delay , new ActionListener () {
338- ArrayList < ArrayList <Tile >> allPath2D = ant .getAllPath2D ();
338+ LinkedList < LinkedList <Tile >> allPath2D = ant .getAllPath2D ();
339339 Tile subNodeToBeDrawn = null ;
340340 Tile mainNode ;
341341
@@ -357,7 +357,7 @@ public void actionPerformed(ActionEvent e) {
357357 }
358358
359359 // add main node which will stay there parmanently to be drawn.
360- ArrayList <Tile > oneIterationArray = allPath2D .get (0 );
360+ LinkedList <Tile > oneIterationArray = allPath2D .get (0 );
361361
362362 if (oneIterationArray .size () > 0 && addMainNode ) {
363363 mainNode = oneIterationArray .get (0 );
@@ -398,7 +398,7 @@ public void animateAnt() {
398398 if (startMovingAnt ) {
399399 double speed = 1.5 ;
400400 int delay = 10 ; // 0.1 second delay
401- ArrayList <Tile > path = ant .getPath ();
401+ LinkedList <Tile > path = ant .getPath ();
402402
403403 // set the ant to the start location
404404 ant .setX (path .get (path .size () - 1 ).getX () * TILE_SIZE );
@@ -473,16 +473,16 @@ protected void paintComponent(Graphics g) {
473473 drawPath (g , TILE_SIZE , tobeDrawn );
474474 } // end paintComponent
475475
476- public void drawPath (Graphics g , int tileSize , ArrayList <Tile > arrayList ) {
476+ public void drawPath (Graphics g , int tileSize , LinkedList <Tile > LinkedList ) {
477477
478- if (arrayList != null && arrayList .size () > 1 ) {
478+ if (LinkedList != null && LinkedList .size () > 1 ) {
479479 g .setColor (Color .RED );
480480
481- for (int i = 0 ; i < arrayList .size () - 1 ; i ++) {
481+ for (int i = 0 ; i < LinkedList .size () - 1 ; i ++) {
482482
483- Tile current = arrayList .get (i );
483+ Tile current = LinkedList .get (i );
484484
485- Tile next = arrayList .get (i + 1 );
485+ Tile next = LinkedList .get (i + 1 );
486486
487487 int x1 = (int ) current .getX () * tileSize + tileSize / 2 ;
488488 int y1 = (int ) current .getY () * tileSize + tileSize / 2 ;
0 commit comments