Add paintShortestPath to MazeAppModel

This commit is contained in:
antograb committed 2017-12-21 09:38:31 +01:00
1 parent 16df6a26c6
commit 9f56d3082a
2 files changed
+19 -2

No files matched your search

+19 -1
View File
@@ -8,6 +8,7 @@ import java.util.Observable;
import java.util.Observer;
import dijkstra.VertexInterface;
import maze.EBox;
import dijkstra.Dijkstra;
import dijkstra.Previous;
@@ -18,11 +19,15 @@ public class MazeAppModel extends Observable {
private VertexInterface arrival = maze.getArrival();
private Previous previous = (Previous) Dijkstra.dijkstra(maze, departure);
private ArrayList<VertexInterface> shortest = previous.getShortestPathTo(arrival);
private ArrayList<VertexInterface> boxList = maze.getVertexes();
//private ArrayList<VertexInterface> boxList = maze.getVertexes();
private Boolean modified = false;
public void setMaze(Maze maze) {
this.maze = new Maze(maze);
this.departure = maze.getDeparture();
this.arrival = maze.getArrival();
this.previous = (Previous) Dijkstra.dijkstra(maze, departure);
this.shortest = previous.getShortestPathTo(arrival);
modified = true;
setChanged();
notifyObservers(maze);
@@ -73,4 +78,17 @@ public class MazeAppModel extends Observable {
}
}
}
public void paintShortestPath(Graphics2D g, int width, int height) {
g.setColor(Color.ORANGE);
int dimensionX = maze.getDimensionX();
int dimensionY = maze.getDimensionY();
int boxWidth = width/dimensionX;
int boxHeight = height/dimensionY;
for (VertexInterface vertex : shortest) {
EBox box = (EBox) vertex;
g.fillOval(box.getX()*boxHeight, box.getY()*boxWidth, boxWidth, boxHeight);
}
}
}