Add code for drawing the labyrinth
This commit is contained in:
parent
69e1646e3f
commit
ed5cfd5cb9
1 changed files with 25 additions and 1 deletions
|
@ -1,11 +1,21 @@
|
||||||
package ch.nuth.zhaw.exbox;
|
package ch.nuth.zhaw.exbox;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
|
||||||
public class LabyrinthServer implements CommandExecutor {
|
public class LabyrinthServer implements CommandExecutor {
|
||||||
ServerGraphics g = new ServerGraphics();
|
ServerGraphics g = new ServerGraphics();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a component for creating graphic content.
|
||||||
|
*
|
||||||
|
* @return A component for creating graphic content.
|
||||||
|
*/
|
||||||
|
public ServerGraphics getGraphics() {
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
public Graph<DijkstraNode, Edge> createGraph(String s) {
|
public Graph<DijkstraNode, Edge> createGraph(String s) {
|
||||||
// TODO implement 8.2
|
// TODO implement 8.2
|
||||||
Graph<DijkstraNode, Edge> graph = new AdjListGraph<>(DijkstraNode.class, Edge.class);
|
Graph<DijkstraNode, Edge> graph = new AdjListGraph<>(DijkstraNode.class, Edge.class);
|
||||||
|
@ -27,6 +37,18 @@ public class LabyrinthServer implements CommandExecutor {
|
||||||
|
|
||||||
public void drawLabyrinth(Graph<DijkstraNode, Edge> graph) {
|
public void drawLabyrinth(Graph<DijkstraNode, Edge> graph) {
|
||||||
// TODO implement 8.3
|
// TODO implement 8.3
|
||||||
|
ServerGraphics graphics = getGraphics();
|
||||||
|
graphics.setColor(Color.GRAY);
|
||||||
|
graphics.fillRect(0, 0, 1, 1);
|
||||||
|
graphics.setColor(Color.WHITE);
|
||||||
|
|
||||||
|
for (DijkstraNode node : graph.getNodes()) {
|
||||||
|
for (Edge edge : node.getEdges()) {
|
||||||
|
if (edge.getDest() instanceof DijkstraNode destination) {
|
||||||
|
graphics.drawPath(node.getName(), destination.getName(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean search(DijkstraNode current, DijkstraNode ziel) {
|
private boolean search(DijkstraNode current, DijkstraNode ziel) {
|
||||||
|
@ -41,9 +63,11 @@ public class LabyrinthServer implements CommandExecutor {
|
||||||
|
|
||||||
public String execute(String s) {
|
public String execute(String s) {
|
||||||
Graph<DijkstraNode, Edge> graph;
|
Graph<DijkstraNode, Edge> graph;
|
||||||
|
ServerGraphics graphics = getGraphics();
|
||||||
|
graphics.clear();
|
||||||
graph = createGraph(s);
|
graph = createGraph(s);
|
||||||
drawLabyrinth(graph);
|
drawLabyrinth(graph);
|
||||||
drawRoute(graph, "0-6", "3-0");
|
drawRoute(graph, "0-6", "3-0");
|
||||||
return g.getTrace();
|
return graphics.getTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue