Fix network synchonization...

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@584 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-06-22 08:31:25 +02:00
parent 21f144f963
commit db71793761

View file

@ -1,5 +1,7 @@
package jrummikub.control.network; package jrummikub.control.network;
import java.util.Date;
import jrummikub.control.RoundControl; import jrummikub.control.RoundControl;
import jrummikub.control.turn.ITurnControl; import jrummikub.control.turn.ITurnControl;
import jrummikub.model.IRoundState; import jrummikub.model.IRoundState;
@ -13,34 +15,35 @@ import jrummikub.view.IView;
*/ */
public class NetworkRoundControl extends RoundControl { public class NetworkRoundControl extends RoundControl {
private IConnectionControl connectionControl; private IConnectionControl connectionControl;
private boolean wasActive; private boolean currentlyActive = false;
private boolean currentlyActive; private boolean inited = false;
/** /**
* Creates new network round control * Creates new network round control
* *
* @param roundState * @param roundState
* current round state * current round state
* @param view * @param view
* the view * the view
* @param connectionControl * @param connectionControl
* connection control for the current connection * connection control for the current connection
* @param startActive * @param startActive
* true for host * true for host
*/ */
public NetworkRoundControl(IRoundState roundState, IView view, public NetworkRoundControl(IRoundState roundState, IView view,
final IConnectionControl connectionControl, boolean startActive) { final IConnectionControl connectionControl, final boolean startActive) {
super(roundState, view, false); super(roundState, view, false);
this.connectionControl = connectionControl; this.connectionControl = connectionControl;
wasActive = startActive;
currentlyActive = startActive;
connections.add(connectionControl.getRoundStateUpdateEvent().add( connections.add(connectionControl.getRoundStateUpdateEvent().add(
new IListener1<IRoundState>() { new IListener1<IRoundState>() {
@Override @Override
public void handle(IRoundState state) { public void handle(IRoundState state) {
setRoundState(state); setRoundState(state);
currentlyActive = startActive;
updateActive();
inited = true;
prepareTurn(); prepareTurn();
} }
})); }));
@ -58,6 +61,17 @@ public class NetworkRoundControl extends RoundControl {
})); }));
} }
private void updateActive() {
switch (roundState.getActivePlayer().getPlayerSettings().getType()) {
case HUMAN:
currentlyActive = true;
break;
case NETWORK:
currentlyActive = false;
break;
}
}
@Override @Override
protected void addTurnControlListeners(ITurnControl turnControl) { protected void addTurnControlListeners(ITurnControl turnControl) {
turnControl.getTableUpdateEvent().add(new IListener1<ITable>() { turnControl.getTableUpdateEvent().add(new IListener1<ITable>() {
@ -79,22 +93,12 @@ public class NetworkRoundControl extends RoundControl {
@Override @Override
protected void prepareTurn() { protected void prepareTurn() {
switch (roundState.getActivePlayer().getPlayerSettings().getType()) { if (!inited) {
case HUMAN: return;
currentlyActive = true;
break;
case NETWORK:
currentlyActive = false;
break;
} }
doPrepareTurn(); updateActive();
super.prepareTurn();
if (showStartTurnPanel() == null) {
if (currentlyActive) {
connectionControl.startTurn();
}
}
} }
@Override @Override
@ -108,9 +112,7 @@ public class NetworkRoundControl extends RoundControl {
protected void deal() { protected void deal() {
super.deal(); super.deal();
if (currentlyActive) { connectionControl.updateRoundState(roundState);
connectionControl.updateRoundState(roundState);
}
} }
@Override @Override