Skip to content

Commit 0089254

Browse files
committed
remove duplicate image loading
1 parent 781c061 commit 0089254

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

src/main/java/Ant.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,15 @@ public class Ant {
2323
private AStarSearch aStarSearch;
2424
private LinkedList<LinkedList<Tile>> allPath2D = new LinkedList<LinkedList<Tile>>();
2525

26-
public Ant(Tile start, Tile goal, int tileSize, Tile[][] tiles) {
26+
public Ant(Tile start, Tile goal, int tileSize, Tile[][] tiles, Image antImage) {
2727
this.start = start;
2828
this.goal = goal;
2929
this.tiles = tiles;
30-
loadAntImg();
30+
this.antImage = antImage;
3131
antX = start.getXpixel();
3232
antY = start.getYpixel();
3333
}
3434

35-
private void loadAntImg() {
36-
try {
37-
antImage = ImageIO.read(getClass().getResource("/assets/images/ant.png"));
38-
} catch (IOException e) {
39-
e.printStackTrace();
40-
}
41-
}
42-
4335
public void draw(Graphics g, int tileSize) {
4436
g.drawImage(antImage, antX, antY, tileSize, tileSize, null);
4537
}

src/main/java/Game.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public void actionPerformed(ActionEvent e) {
317317

318318
if (startTile != null && goalTile != null) {
319319
resetCameFrom(tiles); // useful if the user wants to search for the second time or more
320-
ant = new Ant(startTile, goalTile, TILE_SIZE, tiles);
320+
ant = new Ant(startTile, goalTile, TILE_SIZE, tiles, antImage);
321321
startClicked = true;
322322
startTimeBeforeAnimation = System.currentTimeMillis();
323323
ant.search();

0 commit comments

Comments
 (0)