diff options
author | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-19 02:47:38 +0200 |
---|---|---|
committer | Bennet Gerlach <bennet_gerlach@web.de> | 2011-06-19 02:47:38 +0200 |
commit | bf24a9279ae23336cc8e14d6e1c40f1a2a0c33a7 (patch) | |
tree | 31ab0066fd1c0737d7b9acf5b858881b468468e7 /src/jrummikub/control/network/AbstractGameBeginControl.java | |
parent | 4ddf87fc9638a7a099c57d650ed878571d0b0954 (diff) | |
download | JRummikub-bf24a9279ae23336cc8e14d6e1c40f1a2a0c33a7.tar JRummikub-bf24a9279ae23336cc8e14d6e1c40f1a2a0c33a7.zip |
Start game button in a network game sends an event
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@479 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/network/AbstractGameBeginControl.java')
-rw-r--r-- | src/jrummikub/control/network/AbstractGameBeginControl.java | 62 |
1 files changed, 39 insertions, 23 deletions
diff --git a/src/jrummikub/control/network/AbstractGameBeginControl.java b/src/jrummikub/control/network/AbstractGameBeginControl.java index fd3b546..341f94e 100644 --- a/src/jrummikub/control/network/AbstractGameBeginControl.java +++ b/src/jrummikub/control/network/AbstractGameBeginControl.java @@ -11,7 +11,10 @@ import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; import jrummikub.util.Connection; import jrummikub.util.Event; +import jrummikub.util.Event1; import jrummikub.util.GameData; +import jrummikub.util.IEvent; +import jrummikub.util.IEvent1; import jrummikub.util.IListener; import jrummikub.util.IListener2; import jrummikub.view.ISettingsPanel; @@ -19,7 +22,7 @@ import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.IView; /** - * Abstract class for network game controls inbetween choosing and starting a + * Abstract class for network game controls in between choosing and starting a * game */ public abstract class AbstractGameBeginControl { @@ -28,18 +31,19 @@ public abstract class AbstractGameBeginControl { protected IConnectionControl connectionControl; protected IView view; protected Event backEvent = new Event(); + private Event1<GameData> gameStartEvent = new Event1<GameData>(); /** * Create a new game begin control * * @param connection - * connection control for mesages and events + * connection control for messages and events * @param view - * the view + * the view * @param gameData - * game data of chosen game + * game data of chosen game * @param settingsMode - * mode of settings panel + * mode of settings panel */ public AbstractGameBeginControl(IConnectionControl connection, IView view, final GameData gameData, SettingsMode settingsMode) { @@ -57,11 +61,10 @@ public abstract class AbstractGameBeginControl { new IListener2<String, Color>() { @Override public void handle(String sender, Color color) { - List<PlayerSettings> players = gameData - .getGameSettings().getPlayerList(); + List<PlayerSettings> players = gameData.getGameSettings() + .getPlayerList(); for (PlayerSettings s : players) { - if (s.getName().equals(sender) - && s.getType() == Type.NETWORK) { + if (s.getName().equals(sender) && s.getType() == Type.NETWORK) { s.setColor(color); break; } @@ -72,13 +75,12 @@ public abstract class AbstractGameBeginControl { } private void addViewListeners(IView view, final GameData gameData) { - connections.add(view.getSettingsPanel().getBackEvent().add( - new IListener() { - @Override - public void handle() { - goBack(); - } - })); + connections.add(view.getSettingsPanel().getBackEvent().add(new IListener() { + @Override + public void handle() { + goBack(); + } + })); connections.add(view.getSettingsPanel().getChangePlayerColorEvent() .add(new IListener2<Integer, Color>() { @Override @@ -89,8 +91,8 @@ public abstract class AbstractGameBeginControl { return; } } - PlayerSettings player = gameData.getGameSettings() - .getPlayerList().get(i); + PlayerSettings player = gameData.getGameSettings().getPlayerList() + .get(i); if (player.getType() != Type.HUMAN) { return; } @@ -104,15 +106,29 @@ public abstract class AbstractGameBeginControl { protected abstract void goBack(); /** - * The back event is emitted when the player wants to go back to the - * previous control and panel + * The back event is emitted when the player wants to go back to the previous + * control and panel * * @return the event */ - public Event getBackEvent() { + public IEvent getBackEvent() { return backEvent; } + /** + * The event that is emitted when the game is started + * + * @return the event + */ + public IEvent1<GameData> getStartTurnEvent() { + return gameStartEvent; + } + + protected void startGame() { + abort(); + gameStartEvent.emit(gameData); + } + protected void abort() { view.showSettingsPanel(false); for (Connection c : connections) { @@ -123,8 +139,8 @@ public abstract class AbstractGameBeginControl { protected void updateSettingsPanel() { view.getSettingsPanel().setGameSettings(gameData.getGameSettings()); - Set<Color> colors = new HashSet<Color>(Arrays - .asList(ISettingsPanel.PLAYER_COLORS)); + Set<Color> colors = new HashSet<Color>( + Arrays.asList(ISettingsPanel.PLAYER_COLORS)); for (PlayerSettings player : gameData.getGameSettings().getPlayerList()) { colors.remove(player.getColor()); |