diff --git a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java b/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java index d558acb57546382eaa22b192fd1471938b980287..c0cb4a3ce11757f05ddf2dad40f6b73c74a32273 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java @@ -1,12 +1,18 @@ package edu.ntnu.stud.chaosgame.controller; import edu.ntnu.stud.chaosgame.model.game.ChaosCanvas; +import edu.ntnu.stud.chaosgame.model.game.ChaosGame; import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription; /** - * Observer class for monitoring changes to the active - * ChaosGameDescription {@link ChaosGameDescription} or the canvas {@link ChaosCanvas} + * Observer interface for monitoring changes to the active + * */ -public class ChaosGameObserver { -// TODO: Create class +public interface ChaosGameObserver { +// TODO: Create interface + + /** + * Perform update + */ + void update(ChaosGame game); } diff --git a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java index 26d2f5fe215e697a07adbc65b7651fd96ee3ba04..154a5e05fc6d50754b91e8e9c6a2c985e35002bf 100644 --- a/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java +++ b/src/main/java/edu/ntnu/stud/chaosgame/model/game/ChaosGame.java @@ -1,6 +1,9 @@ package edu.ntnu.stud.chaosgame.model.game; +import edu.ntnu.stud.chaosgame.controller.ChaosGameObserver; import edu.ntnu.stud.chaosgame.model.data.Vector2D; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Random; /** @@ -19,9 +22,9 @@ public class ChaosGame { private ChaosGameDescription description; /** - * The description for this ChaosGame + * Observers monitoring this ChaosGame. */ - // private ChaosGameDescription description; + private ArrayList<ChaosGameObserver> observers; /** * The current point in the chaos game. @@ -38,6 +41,11 @@ public class ChaosGame { */ private int numOfTransforms; + /** + * Basic parameterised constructor. + * @param description the ChaosGameDescription. + * @param canvas the ChaosCanvas. + */ public ChaosGame(ChaosGameDescription description, ChaosCanvas canvas) { this.canvas = canvas; this.description = description; @@ -46,6 +54,21 @@ public class ChaosGame { this.currentPoint = new Vector2D(0, 0); } + /** + * Parameterised constructor with observers + * @param description the ChaosGameDescription. + * @param canvas the ChaosCanvas. + * @param observers the ChaosGameObservers to be added. + */ + public ChaosGame(ChaosGameDescription description, ChaosCanvas canvas, ChaosGameObserver... observers) { + 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)); + } + /** * Get the canvas of this chaos game. * @return the canvas.