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
This commit is contained in:
Matthias Schiffer 2011-06-22 04:59:28 +02:00
parent 9ced7cf953
commit 079de08aea
5 changed files with 161 additions and 124 deletions

View file

@ -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");

View file

@ -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;
connections.add(connectionControl.getParticipantLeftEvent().add(
new IListener1<String>() {
@Override
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();
}
}));
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