summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/RoundControl.java14
-rw-r--r--src/jrummikub/control/network/ConnectionControl.java43
-rw-r--r--src/jrummikub/control/network/IConnectionControl.java9
-rw-r--r--src/jrummikub/control/network/NetworkRoundControl.java31
4 files changed, 91 insertions, 6 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index aeff095..71980e1 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -264,7 +264,7 @@ public class RoundControl {
return TurnControlFactory.getFactory(type).create();
}
- void deal() {
+ protected void deal() {
for (int i = 0; i < roundState.getPlayerCount(); i++) {
IHand hand = roundState.getNthNextPlayer(i).getHand();
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
@@ -276,8 +276,9 @@ public class RoundControl {
}
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
- boolean wasHuman = (turnControl instanceof HumanTurnControl);
- boolean wasAI = (turnControl instanceof AIControl);
+ boolean wasAI = turnControl instanceof AIControl;
+ boolean wasHuman = turnControl instanceof HumanTurnControl;
+
turnControl = null;
view.getTablePanel().setStoneSets(invalidTurnInfo.getTable());
@@ -314,10 +315,13 @@ public class RoundControl {
}
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
- nextPlayer();
+
+ if (wasHuman || wasAI) {
+ nextPlayer();
+ }
}
- private void nextPlayer() {
+ protected void nextPlayer() {
view.setSelectedStones(Collections.<Stone> emptyList());
view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
view.setStoneCollectionHidden(false);
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java
index 4ed160a..c63259d 100644
--- a/src/jrummikub/control/network/ConnectionControl.java
+++ b/src/jrummikub/control/network/ConnectionControl.java
@@ -85,9 +85,11 @@ public class ConnectionControl implements IConnectionControl {
private Event gameStartEvent = new Event();
private Event roundStartEvent = new Event();
+ private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
private Event1<ITable> tableUpdateEvent = new Event1<ITable>();
private Event2<IRoundState, InvalidTurnInfo> turnEndEvent = new Event2<IRoundState, InvalidTurnInfo>();
+ private Event nextPlayerEvent = new Event();
private Event turnStartEvent = new Event();
private GameData currentGame;
@@ -182,6 +184,11 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
+ public IEvent1<IRoundState> getRoundStateUpdateEvent() {
+ return roundStateUpdateEvent;
+ }
+
+ @Override
public IEvent1<ITable> getTableUpdateEvent() {
return tableUpdateEvent;
}
@@ -192,6 +199,11 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
+ public IEvent getNextPlayerEvent() {
+ return nextPlayerEvent;
+ }
+
+ @Override
public IEvent getTurnStartEvent() {
return turnStartEvent;
}
@@ -313,6 +325,20 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
+ public void updateRoundState(final IRoundState roundState) {
+ final UUID uuid = currentGame.getGameID();
+ run(new SendRunner() {
+ @Override
+ protected void addData(DefaultPacketExtension extension) {
+ extension.setValue("messageType", "round_state_update");
+ extension.setValue("uuid", uuid.toString());
+ extension.setValue("state",
+ Base64.encodeObject(roundState, Base64.GZIP));
+ }
+ });
+ }
+
+ @Override
public void updateTable(final ITable table) {
final UUID uuid = currentGame.getGameID();
run(new SendRunner() {
@@ -341,6 +367,18 @@ public class ConnectionControl implements IConnectionControl {
}
@Override
+ public void nextPlayer() {
+ final UUID uuid = currentGame.getGameID();
+ run(new SendRunner() {
+ @Override
+ protected void addData(DefaultPacketExtension extension) {
+ extension.setValue("messageType", "next_player");
+ extension.setValue("uuid", uuid.toString());
+ }
+ });
+ }
+
+ @Override
public void startTurn() {
final UUID uuid = currentGame.getGameID();
run(new SendRunner() {
@@ -459,6 +497,9 @@ public class ConnectionControl implements IConnectionControl {
gameStartEvent.emit();
} else if (messageType.equals("round_start")) {
roundStartEvent.emit();
+ } else if (messageType.equals("round_state_update")) {
+ roundStateUpdateEvent.emit((IRoundState) Base64.decodeToObject(extension
+ .getValue("state")));
} else if (messageType.equals("table_update")) {
tableUpdateEvent.emit((ITable) Base64.decodeToObject(extension
.getValue("table")));
@@ -466,6 +507,8 @@ public class ConnectionControl implements IConnectionControl {
TurnEndData data = (TurnEndData) Base64.decodeToObject(extension
.getValue("data"));
turnEndEvent.emit(data.getRoundState(), data.getInvalidTurnInfo());
+ } else if (messageType.equals("next_player")) {
+ nextPlayerEvent.emit();
} else if (messageType.equals("turn_start")) {
turnStartEvent.emit();
} else {
diff --git a/src/jrummikub/control/network/IConnectionControl.java b/src/jrummikub/control/network/IConnectionControl.java
index b93748c..667a4f9 100644
--- a/src/jrummikub/control/network/IConnectionControl.java
+++ b/src/jrummikub/control/network/IConnectionControl.java
@@ -40,10 +40,14 @@ interface IConnectionControl {
public IEvent getRoundStartEvent();
+ public IEvent1<IRoundState> getRoundStateUpdateEvent();
+
public IEvent1<ITable> getTableUpdateEvent();
public IEvent2<IRoundState, InvalidTurnInfo> getTurnEndEvent();
+ public IEvent getNextPlayerEvent();
+
public IEvent getTurnStartEvent();
public void offerGame(GameData data);
@@ -66,10 +70,13 @@ interface IConnectionControl {
public void startRound();
+ public void updateRoundState(IRoundState roundState);
+
public void updateTable(ITable table);
public void endTurn(IRoundState state, InvalidTurnInfo invalidTurnInfo);
- public void startTurn();
+ public void nextPlayer();
+ public void startTurn();
} \ No newline at end of file
diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java
index 64faebb..d21e8e8 100644
--- a/src/jrummikub/control/network/NetworkRoundControl.java
+++ b/src/jrummikub/control/network/NetworkRoundControl.java
@@ -20,12 +20,27 @@ public class NetworkRoundControl extends RoundControl {
this.connectionControl = connectionControl;
currentlyActive = startActive;
+ connections.add(connectionControl.getRoundStateUpdateEvent().add(
+ new IListener1<IRoundState>() {
+ @Override
+ public void handle(IRoundState state) {
+ NetworkControl.fixGameSettings(state.getGameSettings(),
+ connectionControl.getNickname());
+ setRoundState(state);
+ }
+ }));
connections.add(connectionControl.getTurnStartEvent().add(new IListener() {
@Override
public void handle() {
startTurn();
}
}));
+ connections.add(connectionControl.getNextPlayerEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ NetworkRoundControl.super.nextPlayer();
+ }
+ }));
}
@Override
@@ -68,6 +83,22 @@ public class NetworkRoundControl extends RoundControl {
}
@Override
+ protected void deal() {
+ super.deal();
+
+ if (currentlyActive) {
+ connectionControl.updateRoundState(roundState);
+ }
+ }
+
+ @Override
+ protected void nextPlayer() {
+ if (currentlyActive) {
+ connectionControl.nextPlayer();
+ }
+ }
+
+ @Override
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
if (currentlyActive) {
connectionControl.endTurn(roundState, invalidTurnInfo);