Add paintShortestPath to MazeAppModel
This commit is contained in:
1 parent
16df6a26c6
commit
9f56d3082a
2 files changed
+19
-2
No files matched your search
@@ -8,6 +8,7 @@ import java.util.Observable;
|
|||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
import dijkstra.VertexInterface;
|
import dijkstra.VertexInterface;
|
||||||
|
import maze.EBox;
|
||||||
import dijkstra.Dijkstra;
|
import dijkstra.Dijkstra;
|
||||||
import dijkstra.Previous;
|
import dijkstra.Previous;
|
||||||
|
|
||||||
@@ -18,11 +19,15 @@ public class MazeAppModel extends Observable {
|
|||||||
private VertexInterface arrival = maze.getArrival();
|
private VertexInterface arrival = maze.getArrival();
|
||||||
private Previous previous = (Previous) Dijkstra.dijkstra(maze, departure);
|
private Previous previous = (Previous) Dijkstra.dijkstra(maze, departure);
|
||||||
private ArrayList<VertexInterface> shortest = previous.getShortestPathTo(arrival);
|
private ArrayList<VertexInterface> shortest = previous.getShortestPathTo(arrival);
|
||||||
private ArrayList<VertexInterface> boxList = maze.getVertexes();
|
//private ArrayList<VertexInterface> boxList = maze.getVertexes();
|
||||||
private Boolean modified = false;
|
private Boolean modified = false;
|
||||||
|
|
||||||
public void setMaze(Maze maze) {
|
public void setMaze(Maze maze) {
|
||||||
this.maze = new 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;
|
modified = true;
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(maze);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +30,6 @@ public class MazeDrawing extends JPanel {
|
|||||||
int height = getHeight();
|
int height = getHeight();
|
||||||
|
|
||||||
mazeApp.getMazeAppModel().paintMaze(g2d, width, height);
|
mazeApp.getMazeAppModel().paintMaze(g2d, width, height);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyForUpdates(Object param) {
|
public void notifyForUpdates(Object param) {
|
||||||
|
|||||||
Reference in new issue
Block a user