diff options
Diffstat (limited to 'src/jrummikub/control/network')
-rw-r--r-- | src/jrummikub/control/network/GameOfferControl.java | 4 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkGameControl.java | 53 |
2 files changed, 37 insertions, 20 deletions
diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java index 91b0940..b247a1c 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -1,7 +1,6 @@ package jrummikub.control.network; import java.util.Iterator; -import java.util.List; import java.util.UUID; import jrummikub.model.GameSettings; @@ -107,8 +106,7 @@ public class GameOfferControl extends AbstractGameBeginControl { } private void handleLeave(String nickname) { - List<PlayerSettings> players = gameData.getGameSettings().getPlayerList(); - for (PlayerSettings s : players) { + for (PlayerSettings s : gameData.getGameSettings().getPlayerList()) { if (s.getName().equals(nickname) && s.getType() == Type.NETWORK) { s.setType(Type.VACANT); s.setName("Offen"); diff --git a/src/jrummikub/control/network/NetworkGameControl.java b/src/jrummikub/control/network/NetworkGameControl.java index d053e92..768f0c3 100644 --- a/src/jrummikub/control/network/NetworkGameControl.java +++ b/src/jrummikub/control/network/NetworkGameControl.java @@ -5,7 +5,10 @@ import jrummikub.control.RoundControl; import jrummikub.control.SaveControl; import jrummikub.model.GameSettings; import jrummikub.model.IRoundState; +import jrummikub.model.PlayerSettings; +import jrummikub.model.PlayerSettings.Type; import jrummikub.util.IListener; +import jrummikub.util.IListener1; import jrummikub.view.IView; import jrummikub.view.IView.BottomPanelType; @@ -20,34 +23,51 @@ public class NetworkGameControl extends GameControl { * Creates new network game control * * @param gameSettings - * current game settings + * current game settings * @param saveControl - * if there should ever be saving in network mode + * if there should ever be saving in network mode * @param view - * the view + * the view * @param connectionControl - * the current connection + * the current connection * @param host - * of the current game + * of the current game */ - public NetworkGameControl(GameSettings gameSettings, - SaveControl saveControl, IView view, - IConnectionControl connectionControl, boolean host) { + public NetworkGameControl(GameSettings gameSettings, SaveControl saveControl, + final IView view, IConnectionControl connectionControl, boolean host) { super(gameSettings, saveControl, view); this.connectionControl = connectionControl; this.host = host; - } - @Override - protected void startRound() { - connections.add(connectionControl.getRoundStartEvent().add( - new IListener() { + connections.add(connectionControl.getParticipantLeftEvent().add( + new IListener1<String>() { @Override - public void handle() { - NetworkGameControl.super.startRound(); + public void handle(String nickname) { + if (NetworkGameControl.this.gameSettings == null) { + return; + } + + for (PlayerSettings s : NetworkGameControl.this.gameSettings + .getPlayerList()) { + if (s.getName().equals(nickname) && s.getType() == Type.NETWORK) { + abortGame(); + view.setBottomPanel(BottomPanelType.NETWORK_CONNECTION_LOST_PANEL); + return; + } + } } })); + } + + @Override + protected void startRound() { + connections.add(connectionControl.getRoundStartEvent().add(new IListener() { + @Override + public void handle() { + NetworkGameControl.super.startRound(); + } + })); if (host) { connectionControl.startRound(); @@ -61,8 +81,7 @@ public class NetworkGameControl extends GameControl { @Override protected RoundControl createRoundControl(IRoundState roundState) { - return new NetworkRoundControl(roundState, view, connectionControl, - host); + return new NetworkRoundControl(roundState, view, connectionControl, host); } @Override |