From 7346aa64c80e561052195c5efecb0b278c12ed8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?H=C3=A5vard=20Daleng?=
 <142524365+MrMarHVD@users.noreply.github.com>
Date: Wed, 3 Apr 2024 12:51:55 +0200
Subject: [PATCH] Added notifyObservers()-method.

---
 .../stud/chaosgame/controller/ChaosGameObserver.java     | 8 +++++---
 .../edu/ntnu/stud/chaosgame/model/game/ChaosGame.java    | 9 +++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)

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 54c05bc..c21cf74 100644
--- a/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java
+++ b/src/main/java/edu/ntnu/stud/chaosgame/controller/ChaosGameObserver.java
@@ -6,7 +6,7 @@ import edu.ntnu.stud.chaosgame.model.game.ChaosGameDescription;
 
 /**
  * Observer interface for monitoring changes to the active
- *
+ * TODO: Do we want to have separate update methods for the canvas and description or just one for the whole game? (likely the latter)
  */
 public interface ChaosGameObserver {
 // TODO: Create interface
@@ -16,12 +16,14 @@ public interface ChaosGameObserver {
    *
    * @param canvas the canvas.
    */
-  void updateCanvas(ChaosCanvas canvas);
+  //void updateCanvas(ChaosCanvas canvas);
 
   /**
    * Perform update of the ChaosGameDescription.
    *
    * @param description the description.
    */
-  void updateDescription(ChaosGameDescription description);
+  //void updateDescription(ChaosGameDescription description);
+
+  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 26352bf..f253bc2 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
@@ -71,6 +71,15 @@ public class ChaosGame {
     this.observers.addAll(Arrays.asList(observers));
   }
 
+  /**
+   * Notify the observers that a change has occurred in the chaos game.
+   */
+  public void notifyObservers() {
+    for (ChaosGameObserver observer : this.observers) {
+      observer.update(this);
+    }
+  }
+
   /**
    * Get the canvas of this chaos game.
    *
-- 
GitLab