From 794777c2fe8808444d2952d8abe287278d81f119 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Sun, 29 May 2011 20:19:17 +0200 Subject: Neuer Button im WinPanel mit funktion git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@309 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/GameControl.java | 35 ++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src/jrummikub/control/GameControl.java') 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 connections = new ArrayList(); + 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); } -- cgit v1.2.3