Add maze edition functionalities #27

Merged
antograb merged 5 commits from editMaze into mvc 2018-01-01 19:28:25 +00:00
3 changed files with 23 additions and 2 deletions
Showing only changes of commit 43d58c815b - Show all commits

No files matched your search

+5 -1
View File
@@ -35,7 +35,11 @@ public abstract class Box
public ArrayList<VertexInterface> generateNeighbours() { public ArrayList<VertexInterface> generateNeighbours() {
this.neighbourList = maze.generateNeighbours(this); this.neighbourList = maze.generateNeighbours(this);
return maze.generateNeighbours(this) ; return this.neighbourList;
}
public void resetNeighbourList() {
neighbourList = null;
} }
public boolean isWalkable() { public boolean isWalkable() {
+8
View File
@@ -510,4 +510,12 @@ public class Maze
return maze; return maze;
} }
public void resetNeighbourLists() {
for (Box[] line: maze) {
for (Box box: line) {
box.resetNeighbourList();
}
}
}
} }
+10 -1
View File
@@ -37,7 +37,12 @@ public class MazeAppModel extends Observable {
} }
else { else {
previous = (Previous) Dijkstra.dijkstra(maze, departure); previous = (Previous) Dijkstra.dijkstra(maze, departure);
shortest = previous.getShortestPathTo(arrival); if (((Box) arrival).getNeighbourList() == null) {
shortest = null;
}
else {
shortest = previous.getShortestPathTo(arrival);
}
} }
setChanged(); setChanged();
notifyObservers(MazeAppModelMessage.MazeRenewal); notifyObservers(MazeAppModelMessage.MazeRenewal);
@@ -98,12 +103,14 @@ public class MazeAppModel extends Observable {
public void setWBox(int boxLine, int boxRow) { public void setWBox(int boxLine, int boxRow) {
maze.getMaze()[boxLine][boxRow] = new WBox("W", boxLine, boxRow, maze); maze.getMaze()[boxLine][boxRow] = new WBox("W", boxLine, boxRow, maze);
maze.resetNeighbourLists();
initModelFromMaze(); initModelFromMaze();
saved = false; saved = false;
} }
public void setEBox(int boxLine, int boxRow) { public void setEBox(int boxLine, int boxRow) {
maze.getMaze()[boxLine][boxRow] = new EBox("E", boxLine, boxRow, maze); maze.getMaze()[boxLine][boxRow] = new EBox("E", boxLine, boxRow, maze);
maze.resetNeighbourLists();
initModelFromMaze(); initModelFromMaze();
saved = false; saved = false;
} }
@@ -116,6 +123,7 @@ public class MazeAppModel extends Observable {
new EBox("E", departureLine, departureRow, maze); new EBox("E", departureLine, departureRow, maze);
} }
maze.getMaze()[boxLine][boxRow] = new DBox("D", boxLine, boxRow, maze); maze.getMaze()[boxLine][boxRow] = new DBox("D", boxLine, boxRow, maze);
maze.resetNeighbourLists();
initModelFromMaze(); initModelFromMaze();
saved = false; saved = false;
} }
@@ -128,6 +136,7 @@ public class MazeAppModel extends Observable {
new EBox("E", arrivalLine, arrivalRow, maze); new EBox("E", arrivalLine, arrivalRow, maze);
} }
maze.getMaze()[boxLine][boxRow] = new ABox("A", boxLine, boxRow, maze); maze.getMaze()[boxLine][boxRow] = new ABox("A", boxLine, boxRow, maze);
maze.resetNeighbourLists();
initModelFromMaze(); initModelFromMaze();
saved = false; saved = false;
} }