diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-20 04:12:11 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-20 04:12:11 +0200 |
commit | a97b8445a2bf0bd7f0e8b551ece08fba02275159 (patch) | |
tree | 4e9669e29128fb648eb5566c45d1415fba412e30 /src | |
parent | f37219cfbf4db6a5ee5d62909155c5b1e47e1085 (diff) | |
download | JRummikub-a97b8445a2bf0bd7f0e8b551ece08fba02275159.tar JRummikub-a97b8445a2bf0bd7f0e8b551ece08fba02275159.zip |
Fix player types in received game settings
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@506 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/control/network/GameJoinControl.java | 17 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkControl.java | 14 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkRoundControl.java | 3 |
3 files changed, 18 insertions, 16 deletions
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<UUID> games = new ArrayList<UUID>(); private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>(); + 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<IRoundState>() { @Override public void handle(IRoundState state) { + NetworkControl.fixGameSettings(state.getGameSettings(), connectionControl.getNickname()); setRoundState(state); startTurn(); |