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/ApplicationControl.java | 16 +++- src/jrummikub/control/GameControl.java | 35 +++++++-- src/jrummikub/control/SettingsControl.java | 101 +++++++++++++++----------- 3 files changed, 102 insertions(+), 50 deletions(-) (limited to 'src/jrummikub/control') diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index 7a3113f..582a08c 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -1,6 +1,11 @@ package jrummikub.control; +import java.util.ArrayList; +import java.util.List; + import jrummikub.model.GameSettings; +import jrummikub.util.Connection; +import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.view.IView; @@ -25,12 +30,21 @@ public class ApplicationControl { * Starts the application by showing the game settings dialog panel */ public void startApplication() { - SettingsControl settingsControl = new SettingsControl(view, new GameSettings()); + view.showScorePanel(false); + view.enableWinPanel(false); + SettingsControl settingsControl = new SettingsControl(view, + new GameSettings()); settingsControl.getStartGameEvent().add(new IListener1() { @Override public void handle(GameSettings settings) { GameControl gameControl = new GameControl(settings, view); + gameControl.getEndOfGameEvent().add(new IListener() { + @Override + public void handle() { + startApplication(); + } + }); gameControl.startGame(); } 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); } diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index 42d3659..dfaa552 100644 --- a/src/jrummikub/control/SettingsControl.java +++ b/src/jrummikub/control/SettingsControl.java @@ -1,9 +1,12 @@ package jrummikub.control; import java.awt.Color; +import java.util.ArrayList; +import java.util.List; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; +import jrummikub.util.Connection; import jrummikub.util.Event1; import jrummikub.util.IEvent1; import jrummikub.util.IListener; @@ -18,6 +21,7 @@ import jrummikub.view.IView; public class SettingsControl { private IView view; private Event1 startGameEvent = new Event1(); + private List connections = new ArrayList(); private GameSettings settings; @@ -25,9 +29,9 @@ public class SettingsControl { * Create a new settings control * * @param view - * the view to use + * the view to use * @param settings - * initial game settings + * initial game settings */ public SettingsControl(IView view, GameSettings settings) { this.view = view; @@ -37,8 +41,8 @@ public class SettingsControl { } /** - * the start game event is emitted when the user wants to start a game and the - * settings made are valid + * the start game event is emitted when the user wants to start a game and + * the settings made are valid * * @return the event */ @@ -50,64 +54,70 @@ public class SettingsControl { * Start the operation of the settings control */ public void startSettings() { - view.getSettingsPanel().setInitialMeldThreshold(settings.getInitialMeldThreshold()); + view.getSettingsPanel().setInitialMeldThreshold( + settings.getInitialMeldThreshold()); view.getSettingsPanel().setJokerNumber(settings.getJokerNumber()); - - view.getSettingsPanel().getChangeInitialMeldThresholdEvent().add(new IListener1() { - @Override - public void handle(Integer value) { - settings.setInitialMeldThreshold(value); - update(); - } - }); - - view.getSettingsPanel().getChangeJokerNumberEvent().add(new IListener1() { - @Override - public void handle(Integer value) { - settings.setJokerNumber(value); - update(); - } - }); - + + connections.add(view.getSettingsPanel() + .getChangeInitialMeldThresholdEvent() + .add(new IListener1() { + @Override + public void handle(Integer value) { + settings.setInitialMeldThreshold(value); + update(); + } + })); + + connections.add(view.getSettingsPanel().getChangeJokerNumberEvent() + .add(new IListener1() { + @Override + public void handle(Integer value) { + settings.setJokerNumber(value); + update(); + } + })); + addPlayerSettingsListeners(); view.showSettingsPanel(true); } private void addPlayerSettingsListeners() { - view.getSettingsPanel().getStartGameEvent().add(new IListener() { - @Override - public void handle() { - startGame(); - } - }); - view.getSettingsPanel().getAddPlayerEvent().add(new IListener() { - @Override - public void handle() { - addPlayer(); - } - }); - view.getSettingsPanel().getRemovePlayerEvent() + connections.add(view.getSettingsPanel().getStartGameEvent() + .add(new IListener() { + @Override + public void handle() { + startGame(); + } + })); + connections.add(view.getSettingsPanel().getAddPlayerEvent() + .add(new IListener() { + @Override + public void handle() { + addPlayer(); + } + })); + connections.add(view.getSettingsPanel().getRemovePlayerEvent() .add(new IListener1() { @Override public void handle(Integer i) { removePlayer(i); } - }); - view.getSettingsPanel().getChangePlayerColorEvent() + })); + connections.add(view.getSettingsPanel().getChangePlayerColorEvent() .add(new IListener2() { @Override public void handle(Integer i, Color color) { setPlayerColor(i, color); } - }); - view.getSettingsPanel().getChangePlayerNameEvent() + })); + connections.add(view.getSettingsPanel().getChangePlayerNameEvent() .add(new IListener2() { @Override public void handle(Integer i, String name) { setPlayerName(i, name); } - }); + })); } private void addPlayer() { @@ -142,7 +152,8 @@ public class SettingsControl { break; } - settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color)); + settings.getPlayerList().add( + new PlayerSettings("Spieler " + num, color)); update(); } @@ -178,8 +189,9 @@ public class SettingsControl { private void update() { view.getSettingsPanel().enableRemovePlayerButtons( settings.getPlayerList().size() > 2); - view.getSettingsPanel().enableAddPlayerButton( - settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); + view.getSettingsPanel() + .enableAddPlayerButton( + settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); checkSettings(); @@ -220,6 +232,9 @@ public class SettingsControl { view.showSettingsPanel(false); + for (Connection c : connections) { + c.remove(); + } startGameEvent.emit(settings); } } -- cgit v1.2.3