Fix Game and add: Observer
This commit is contained in:
@@ -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<Observer> 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.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user