summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/network
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/network')
-rw-r--r--src/jrummikub/control/network/NetworkRoundControl.java54
1 files changed, 28 insertions, 26 deletions
diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java
index 05a3424..c8731ee 100644
--- a/src/jrummikub/control/network/NetworkRoundControl.java
+++ b/src/jrummikub/control/network/NetworkRoundControl.java
@@ -1,5 +1,7 @@
package jrummikub.control.network;
+import java.util.Date;
+
import jrummikub.control.RoundControl;
import jrummikub.control.turn.ITurnControl;
import jrummikub.model.IRoundState;
@@ -13,34 +15,35 @@ import jrummikub.view.IView;
*/
public class NetworkRoundControl extends RoundControl {
private IConnectionControl connectionControl;
- private boolean wasActive;
- private boolean currentlyActive;
+ private boolean currentlyActive = false;
+ private boolean inited = false;
/**
* Creates new network round control
*
* @param roundState
- * current round state
+ * current round state
* @param view
- * the view
+ * the view
* @param connectionControl
- * connection control for the current connection
+ * connection control for the current connection
* @param startActive
- * true for host
+ * true for host
*/
public NetworkRoundControl(IRoundState roundState, IView view,
- final IConnectionControl connectionControl, boolean startActive) {
+ final IConnectionControl connectionControl, final boolean startActive) {
super(roundState, view, false);
this.connectionControl = connectionControl;
- wasActive = startActive;
- currentlyActive = startActive;
connections.add(connectionControl.getRoundStateUpdateEvent().add(
new IListener1<IRoundState>() {
@Override
public void handle(IRoundState state) {
setRoundState(state);
+ currentlyActive = startActive;
+ updateActive();
+ inited = true;
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
protected void addTurnControlListeners(ITurnControl turnControl) {
turnControl.getTableUpdateEvent().add(new IListener1<ITable>() {
@@ -79,22 +93,12 @@ public class NetworkRoundControl extends RoundControl {
@Override
protected void prepareTurn() {
- switch (roundState.getActivePlayer().getPlayerSettings().getType()) {
- case HUMAN:
- currentlyActive = true;
- break;
- case NETWORK:
- currentlyActive = false;
- break;
+ if (!inited) {
+ return;
}
- doPrepareTurn();
-
- if (showStartTurnPanel() == null) {
- if (currentlyActive) {
- connectionControl.startTurn();
- }
- }
+ updateActive();
+ super.prepareTurn();
}
@Override
@@ -108,9 +112,7 @@ public class NetworkRoundControl extends RoundControl {
protected void deal() {
super.deal();
- if (currentlyActive) {
- connectionControl.updateRoundState(roundState);
- }
+ connectionControl.updateRoundState(roundState);
}
@Override