diff --git a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java index 72842ff..69fccdc 100644 --- a/src/main/java/it/polimi/ingsw/gc14/Model/Game.java +++ b/src/main/java/it/polimi/ingsw/gc14/Model/Game.java @@ -17,7 +17,7 @@ import it.polimi.ingsw.gc14.Model.GamePackage.GameStages; import java.io.Serializable; import java.util.*; import java.util.stream.Collectors; - +import it.polimi.ingsw.gc14.Network.Observer; /** * Represents the main game model. * A Game object stores the players, the current state of the match, @@ -25,6 +25,18 @@ import java.util.stream.Collectors; */ public class Game implements Serializable { + private transient List observers = new ArrayList<>(); // transient! non serializzare + + public void addObserver(Observer observer) { + observers.add(observer); + } + + private void notifyObservers() { + for (Observer o : observers) { + o.update(this); + } + } + /** * The list of players participating in the game. */ diff --git a/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java b/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java new file mode 100644 index 0000000..7677d92 --- /dev/null +++ b/src/main/java/it/polimi/ingsw/gc14/Network/Observer.java @@ -0,0 +1,7 @@ +package it.polimi.ingsw.gc14.Network; + +import it.polimi.ingsw.gc14.Model.Game; + +public interface Observer { + public void update(Game model); +}