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.io.Serializable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import it.polimi.ingsw.gc14.Network.Observer;
|
||||||
/**
|
/**
|
||||||
* Represents the main game model.
|
* Represents the main game model.
|
||||||
* A Game object stores the players, the current state of the match,
|
* 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 {
|
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.
|
* The list of players participating in the game.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user