diff options
Diffstat (limited to 'src/jrummikub/control/GameControl.java')
-rw-r--r-- | src/jrummikub/control/GameControl.java | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java index 887b80d..9e967c4 100644 --- a/src/jrummikub/control/GameControl.java +++ b/src/jrummikub/control/GameControl.java @@ -9,6 +9,8 @@ import jrummikub.model.IRoundState; import jrummikub.model.RoundState; import jrummikub.model.Score; import jrummikub.util.Connection; +import jrummikub.util.Event; +import jrummikub.util.IEvent; import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.view.IView; @@ -22,14 +24,15 @@ public class GameControl { RoundControl roundControl; private GameState gameState; private List<Connection> connections = new ArrayList<Connection>(); + private Event endOfGameEvent = new Event(); /** * Constructor * * @param gameSettings - * the game settings + * the game settings * @param view - * the view + * the view */ public GameControl(GameSettings gameSettings, IView view) { this.gameSettings = gameSettings; @@ -45,14 +48,33 @@ public class GameControl { startRound(); } })); - connections.add(view.getFinalScoreEvent().add(new IListener() { + + connections.add(view.getNewGameEvent().add(new IListener() { + @Override + public void handle() { + endGame(); + } + })); + + connections.add(view.getEndProgramEvent().add(new IListener() { @Override public void handle() { - finalScore(); + endProgram(); } })); } + public IEvent getEndOfGameEvent() { + return endOfGameEvent; + } + + private void endGame() { + for (Connection c : connections) { + c.remove(); + } + endOfGameEvent.emit(); + } + /** * Game gets started by initializing the first Round */ @@ -105,12 +127,13 @@ public class GameControl { view.getScorePanel().setPlayers(gameSettings.getPlayerList()); view.getScorePanel().setScores(gameState.getScores()); - view.getScorePanel().setAccumulatedScore(gameState.getAccumulatedScore()); + view.getScorePanel().setAccumulatedScore( + gameState.getAccumulatedScore()); view.getScorePanel().update(); view.showScorePanel(true); } - private void finalScore() { + private void endProgram() { System.exit(0); } |