diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java index 9788910bd63e1c74e2ecc43a652f88100f8cdf4f..28c7acdedcae5560eadb015789cab090166a0c34 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/game/ChaosGame.java @@ -36,10 +36,6 @@ public class ChaosGame { */ private Random random; - /** - * Number of transforms. - */ - private int numOfTransforms; /** * Basic parameterised constructor. @@ -51,7 +47,6 @@ public class ChaosGame { this.canvas = canvas; this.description = description; this.random = new Random(); - this.numOfTransforms = description.getTransforms().size(); this.currentPoint = new Vector2D(0, 0); } @@ -66,7 +61,6 @@ public class ChaosGame { this.canvas = canvas; this.description = description; this.random = new Random(); - this.numOfTransforms = description.getTransforms().size(); this.currentPoint = new Vector2D(0, 0); this.observers.addAll(Arrays.asList(observers)); } @@ -86,6 +80,15 @@ public class ChaosGame { */ public Vector2D getCurrentPoint() { return this.currentPoint; } + /** + * Get the chaos game description. + * + * @param description the description to set. + */ + public void setDescription(ChaosGameDescription description) { + this.description = description; + } + /** * Notify the observers that a change has occurred in the ChaosGame. @@ -112,7 +115,7 @@ public class ChaosGame { */ public void runSteps(int n) { for (int i = 0; i < n; i++) { - int j = this.random.nextInt(0, this.numOfTransforms); + int j = this.random.nextInt(0, this.description.getTransforms().size()); //System.out.println("Before transform: " + currentPoint.getX0() + " " + currentPoint.getX1()); this.currentPoint = this.description.getTransforms().get(j).transform(currentPoint); diff --git a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java index f7eedc04f90475a4849d56c41287eaa10cfd9dbc..54354668bc17f3ae0cd44d3bf0e87e929465b938 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGUIView.java @@ -24,7 +24,7 @@ import javafx.util.Duration; import java.io.IOException; import java.util.concurrent.atomic.AtomicReference; -public class ChaosGameGUIView { +public class ChaosGameGUIView implements ChaosGameObserver { private int currentLine = 0; private PixelWriter pixelWriter; @@ -245,4 +245,27 @@ public class ChaosGameGUIView { this.imageView.setImage(inputView); } + /** + * Update the description of the chaos game. + * TODO: this method may need to be changed depending on how we implement the UI. + * + * @param description the description. + */ + @Override + public void updateDescription(ChaosGameDescription description) { + this.game.setDescription(description); + } + + /** + * Update the observer based on changes to the chaos game. + * TODO: this method may need to be changed depending on how we implement the UI. The update method may need to be split. + * + * @param game the game this observer is monitoring. + */ + @Override + public void update(ChaosGame game) { + //drawChaosGame(); + } + + } diff --git a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameObserver.java b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameObserver.java index 24ab6a37de32be6c0e83ee0f0ad346f67c5241be..a9869bde642ec9a5dc4a61552501d03c451352c1 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameObserver.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameObserver.java @@ -1,6 +1,7 @@ package edu.ntnu.stud.chaosgame.view; import edu.ntnu.stud.chaosgame.controller.game.ChaosGame; +import edu.ntnu.stud.chaosgame.controller.game.ChaosGameDescription; /** * Observer interface for monitoring changes to the active @@ -23,6 +24,7 @@ public interface ChaosGameObserver { * @param description the description. */ //void updateDescription(ChaosGameDescription description); + void updateDescription(ChaosGameDescription description); /** * Update the observer based on changes to the chaos game.