diff --git a/src/model/MazeAppModel.java b/src/model/MazeAppModel.java index f46b461..815f3f6 100644 --- a/src/model/MazeAppModel.java +++ b/src/model/MazeAppModel.java @@ -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 shortest = previous.getShortestPathTo(arrival); - private ArrayList boxList = maze.getVertexes(); + //private ArrayList 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); + } + } } diff --git a/src/ui/MazeDrawing.java b/src/ui/MazeDrawing.java index f43e4ea..2a83fe1 100644 --- a/src/ui/MazeDrawing.java +++ b/src/ui/MazeDrawing.java @@ -30,7 +30,6 @@ public class MazeDrawing extends JPanel { int height = getHeight(); mazeApp.getMazeAppModel().paintMaze(g2d, width, height); - } public void notifyForUpdates(Object param) {