summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/network/NetworkRoundControl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/network/NetworkRoundControl.java')
-rw-r--r--src/jrummikub/control/network/NetworkRoundControl.java44
1 files changed, 34 insertions, 10 deletions
diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java
index d7de9ea..a05f8ae 100644
--- a/src/jrummikub/control/network/NetworkRoundControl.java
+++ b/src/jrummikub/control/network/NetworkRoundControl.java
@@ -11,12 +11,22 @@ import jrummikub.view.IView;
public class NetworkRoundControl extends RoundControl {
private IConnectionControl connectionControl;
private boolean currentlyActive;
-
- public NetworkRoundControl(IRoundState roundState, IView view, IConnectionControl connectionControl, boolean startActive) {
+
+ public NetworkRoundControl(IRoundState roundState, IView view,
+ IConnectionControl connectionControl, boolean startActive) {
super(roundState, view);
-
+
this.connectionControl = connectionControl;
currentlyActive = startActive;
+
+ connections.add(connectionControl.getTurnStartEvent().add(
+ new IListener1<IRoundState>() {
+ @Override
+ public void handle(IRoundState state) {
+ NetworkRoundControl.this.roundState = state;
+ startTurn();
+ }
+ }));
}
@Override
@@ -28,7 +38,7 @@ public class NetworkRoundControl extends RoundControl {
}
});
}
-
+
@Override
protected ITurnControl createTurnControl(PlayerSettings playerSettings) {
switch (playerSettings.getType()) {
@@ -39,17 +49,31 @@ public class NetworkRoundControl extends RoundControl {
currentlyActive = false;
break;
}
-
+
if (!currentlyActive) {
return new NetworkTurnControl(connectionControl);
}
-
+
return super.createTurnControl(playerSettings);
}
-
+
@Override
- protected void startTurn() {
- connectionControl.startTurn(roundState);
- super.startTurn();
+ protected void prepareTurn() {
+ boolean wasActive = currentlyActive;
+
+ doPrepareTurn();
+
+ if (wasActive) {
+ connectionControl.startTurn(roundState);
+ }
+ }
+
+ @Override
+ protected void endOfTurn(ITable newTable) {
+ if (currentlyActive) {
+ connectionControl.endTurn(newTable);
+ }
+
+ super.endOfTurn(newTable);
}
}