summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/network/GameJoinControl.java17
-rw-r--r--src/jrummikub/control/network/NetworkControl.java14
-rw-r--r--src/jrummikub/control/network/NetworkRoundControl.java3
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();