summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/network
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-22 04:59:28 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-22 04:59:28 +0200
commit079de08aead67037ba00d1b5612ac9a0240166df (patch)
tree31450c1e4164e86f4da2c09b533fb53e17180a53 /src/jrummikub/control/network
parent9ced7cf9530cb1cc7446dbbae4b5c6a607de01d5 (diff)
downloadJRummikub-079de08aead67037ba00d1b5612ac9a0240166df.tar
JRummikub-079de08aead67037ba00d1b5612ac9a0240166df.zip
Show panel when a player disappears during a game
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@575 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/network')
-rw-r--r--src/jrummikub/control/network/GameOfferControl.java4
-rw-r--r--src/jrummikub/control/network/NetworkGameControl.java53
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