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/ConnectionControl.java29
-rw-r--r--src/jrummikub/control/network/IConnectionControl.java4
-rw-r--r--src/jrummikub/control/network/NetworkRoundControl.java9
-rw-r--r--src/jrummikub/control/network/NetworkTurnControl.java13
4 files changed, 54 insertions, 1 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index 832b067..785350e 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -107,6 +107,7 @@ public class ConnectionControl implements IConnectionControl {
private Event gameStartEvent = new Event();
private Event roundStartEvent = new Event();
+ private Event redealEvent = new Event();
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
private Event1<ITable> tableUpdateEvent = new Event1<ITable>();
@@ -221,6 +222,11 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
+ public IEvent getRedealEvent() {
+ return redealEvent;
+ }
+
+ @Override
public IEvent1<IRoundState> getRoundStateUpdateEvent() {
return roundStateUpdateEvent;
}
@@ -368,6 +374,18 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
+ public void redeal() {
+ final UUID uuid = currentGame.getGameID();
+ run(new SendRunner() {
+ @Override
+ protected void addData(DefaultPacketExtension extension) {
+ extension.setValue("messageType", "redeal");
+ extension.setValue("uuid", uuid.toString());
+ }
+ });
+ }
+
+ @Override
public void updateRoundState(final IRoundState roundState) {
final UUID uuid = currentGame.getGameID();
run(new SendRunner() {
@@ -541,7 +559,16 @@ public class ConnectionControl implements IConnectionControl {
gameStartEvent.emit();
} else if (messageType.equals("round_start")) {
roundStartEvent.emit();
- } else if (messageType.equals("round_state_update")) {
+ } else if (messageType.equals("redeal")) {
+ redealEvent.emit();
+ } else {
+ messagesDuringRound(extension, messageType);
+ }
+ }
+
+ private void messagesDuringRound(DefaultPacketExtension extension,
+ String messageType) {
+ if (messageType.equals("round_state_update")) {
IRoundState state = (IRoundState) Base64.decodeToObject(extension
.getValue("state"));
fixGameSettings(state.getGameSettings());
diff --git a/src/jrummikub/control/network/IConnectionControl.java b/src/jrummikub/control/network/IConnectionControl.java
index 667a4f9..19042c3 100644
--- a/src/jrummikub/control/network/IConnectionControl.java
+++ b/src/jrummikub/control/network/IConnectionControl.java
@@ -40,6 +40,8 @@ interface IConnectionControl {
public IEvent getRoundStartEvent();
+ public IEvent getRedealEvent();
+
public IEvent1<IRoundState> getRoundStateUpdateEvent();
public IEvent1<ITable> getTableUpdateEvent();
@@ -70,6 +72,8 @@ interface IConnectionControl {
public void startRound();
+ public void redeal();
+
public void updateRoundState(IRoundState roundState);
public void updateTable(ITable table);
diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java
index 934abf0..20a4c28 100644
--- a/src/jrummikub/control/network/NetworkRoundControl.java
+++ b/src/jrummikub/control/network/NetworkRoundControl.java
@@ -102,4 +102,13 @@ public class NetworkRoundControl extends RoundControl {
super.endOfTurn(invalidTurnInfo);
}
+
+ @Override
+ protected void redeal() {
+ if (currentlyActive) {
+ connectionControl.redeal();
+ }
+
+ super.redeal();
+ }
}
diff --git a/src/jrummikub/control/network/NetworkTurnControl.java b/src/jrummikub/control/network/NetworkTurnControl.java
index dacc892..07d46ba 100644
--- a/src/jrummikub/control/network/NetworkTurnControl.java
+++ b/src/jrummikub/control/network/NetworkTurnControl.java
@@ -6,6 +6,7 @@ import jrummikub.model.IRoundState;
import jrummikub.model.ITable;
import jrummikub.util.Event1;
import jrummikub.util.IEvent1;
+import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.IListener2;
@@ -37,6 +38,12 @@ public class NetworkTurnControl extends AbstractTurnControl {
endOfTurn(state, invalidTurnInfo);
}
}));
+ connections.add(connectionControl.getRedealEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ redeal();
+ }
+ }));
timer.startTimer();
}
@@ -47,6 +54,12 @@ public class NetworkTurnControl extends AbstractTurnControl {
endOfTurnEvent.emit(roundState, invalidTurnInfo);
}
+ private void redeal() {
+ cleanUp();
+
+ redealEvent.emit();
+ }
+
@Override
protected void timeOut() {
}