From d9e92e31af67849e71618c6f97d3a62754c1bac2 Mon Sep 17 00:00:00 2001 From: Oshgnacknak Date: Wed, 30 Jun 2021 18:46:10 +0200 Subject: [PATCH] Pass factory via constructor --- .../java/de/oshgnacknak/gruphi/Gruphi.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/oshgnacknak/gruphi/Gruphi.java b/src/main/java/de/oshgnacknak/gruphi/Gruphi.java index cc23b32..976136b 100644 --- a/src/main/java/de/oshgnacknak/gruphi/Gruphi.java +++ b/src/main/java/de/oshgnacknak/gruphi/Gruphi.java @@ -1,7 +1,7 @@ package de.oshgnacknak.gruphi; import h07.graph.DirectedGraph; -import h07.graph.EmptyGraphFactory; +import h07.graph.DirectedGraphFactory; import javax.swing.*; import java.awt.*; @@ -17,18 +17,21 @@ class Gruphi extends JFrame { private static final double VEL = 5; private static final double NEIGHBOUR_DISTANCE = 50; - DirectedGraph graph = newGraph(); + private final DirectedGraph graph; - MazeGenerator mazeGenerator = new MazeGenerator<>(graph, (a, b) -> - a.pos.dist(b.pos) <= NEIGHBOUR_DISTANCE); + private final MazeGenerator mazeGenerator; - Node selected = null; - Vector vel = new Vector(0, 0); + private Node selected = null; + private final Vector vel = new Vector(0, 0); private boolean running = true; - Gruphi() { + Gruphi(DirectedGraphFactory factory) { super("Gruphi - The Graph GUI - By Osh"); + this.graph = factory.createDirectedGraph(); + this. mazeGenerator = new MazeGenerator<>(graph, (a, b) -> + a.pos.dist(b.pos) <= NEIGHBOUR_DISTANCE); + add(new Canvas(this::draw)); pack(); setLocationRelativeTo(null); @@ -198,7 +201,7 @@ class Gruphi extends JFrame { .findFirst(); } - void draw(Drawable d) { + private void draw(Drawable d) { d.fill(Color.BLACK); d.rect(0, 0, getWidth(), getHeight()); @@ -247,20 +250,17 @@ class Gruphi extends JFrame { } } - void update() { + private void update() { if (selected != null) { selected.pos.add(vel); } } - DirectedGraph newGraph() { - return new EmptyGraphFactory().createDirectedGraph(); - } - public static void main(String[] args) { - var gruphi = new Gruphi(); - gruphi.setVisible(true); - gruphi.updateLoop(); - System.exit(0); + // TODO: + // var gruphi = new Gruphi(new SomeFactory<>()); + // gruphi.setVisible(true); + // gruphi.updateLoop(); + // System.exit(0); } }