From a97b8445a2bf0bd7f0e8b551ece08fba02275159 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 20 Jun 2011 04:12:11 +0200 Subject: Fix player types in received game settings git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@506 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/network/GameJoinControl.java | 17 ++--------------- src/jrummikub/control/network/NetworkControl.java | 14 ++++++++++++++ src/jrummikub/control/network/NetworkRoundControl.java | 3 ++- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src/jrummikub/control/network') diff --git a/src/jrummikub/control/network/GameJoinControl.java b/src/jrummikub/control/network/GameJoinControl.java index 5d31e74..d846ebc 100644 --- a/src/jrummikub/control/network/GameJoinControl.java +++ b/src/jrummikub/control/network/GameJoinControl.java @@ -3,8 +3,6 @@ package jrummikub.control.network; import java.util.UUID; import jrummikub.model.GameSettings; -import jrummikub.model.PlayerSettings; -import jrummikub.model.PlayerSettings.Type; import jrummikub.util.Event; import jrummikub.util.GameData; import jrummikub.util.IEvent; @@ -33,7 +31,7 @@ public class GameJoinControl extends AbstractGameBeginControl { final GameData gameData, final IView view) { super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN); - fixGameSettings(gameData.getGameSettings()); + NetworkControl.fixGameSettings(gameData.getGameSettings(), connectionControl.getNickname()); updateSettingsPanel(); connections.add(connectionControl.getGameOfferEvent().add( @@ -43,7 +41,7 @@ public class GameJoinControl extends AbstractGameBeginControl { if (data.getGameID().equals(gameData.getGameID())) { GameSettings settings = data.getGameSettings(); - fixGameSettings(settings); + NetworkControl.fixGameSettings(settings, connectionControl.getNickname()); gameData.setGameSettings(settings); @@ -81,17 +79,6 @@ public class GameJoinControl extends AbstractGameBeginControl { return gameStartEvent; } - private void fixGameSettings(GameSettings settings) { - for (PlayerSettings player : settings.getPlayerList()) { - if (player.getType() == Type.HUMAN) { - player.setType(Type.NETWORK); - } else if (player.getType() == Type.NETWORK - && player.getName().equals(connectionControl.getNickname())) { - player.setType(Type.HUMAN); - } - } - } - /** * Starts the join control and sets the settings panel in game join mode */ diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index 6d43cac..0d0fbe9 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -8,6 +8,8 @@ import java.util.UUID; import jrummikub.control.SaveControl; import jrummikub.model.GameSettings; +import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; import jrummikub.util.Connection; import jrummikub.util.Event; import jrummikub.util.GameData; @@ -39,6 +41,18 @@ public class NetworkControl { private List games = new ArrayList(); private Map gameMap = new HashMap(); + public static void fixGameSettings(GameSettings settings, String nickname) { + for (PlayerSettings player : settings.getPlayerList()) { + if (player.getType() == Type.HUMAN) { + player.setType(Type.NETWORK); + } + + if (player.getType() == Type.NETWORK && player.getName().equals(nickname)) { + player.setType(Type.HUMAN); + } + } + } + /** * Creates a new network control * diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java index f500b18..a9775b7 100644 --- a/src/jrummikub/control/network/NetworkRoundControl.java +++ b/src/jrummikub/control/network/NetworkRoundControl.java @@ -13,7 +13,7 @@ public class NetworkRoundControl extends RoundControl { private boolean currentlyActive; public NetworkRoundControl(IRoundState roundState, IView view, - IConnectionControl connectionControl, boolean startActive) { + final IConnectionControl connectionControl, boolean startActive) { super(roundState, view); this.connectionControl = connectionControl; @@ -23,6 +23,7 @@ public class NetworkRoundControl extends RoundControl { new IListener1() { @Override public void handle(IRoundState state) { + NetworkControl.fixGameSettings(state.getGameSettings(), connectionControl.getNickname()); setRoundState(state); startTurn(); -- cgit v1.2.3