Skip to content
Snippets Groups Projects
Commit 655ca676 authored by Håvard Daleng's avatar Håvard Daleng
Browse files

Converted ChaosGameObserver to an interface.

parent 18fcfd41
No related branches found
No related tags found
No related merge requests found
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);
}
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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment