From 6acf9d6078d89eef5d2f2b19372b99baefd122af Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2011 20:44:28 +0200 Subject: Fix redealing in network mode git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@554 72836036-5685-4462-b002-a69064685172 --- .../control/network/ConnectionControl.java | 29 +++++++++++++++++++++- .../control/network/IConnectionControl.java | 4 +++ .../control/network/NetworkRoundControl.java | 9 +++++++ .../control/network/NetworkTurnControl.java | 13 ++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) (limited to 'src/jrummikub/control/network') 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 roundStateUpdateEvent = new Event1(); private Event1 tableUpdateEvent = new Event1(); @@ -220,6 +221,11 @@ public class ConnectionControl implements IConnectionControl { return roundStartEvent; } + @Override + public IEvent getRedealEvent() { + return redealEvent; + } + @Override public IEvent1 getRoundStateUpdateEvent() { return roundStateUpdateEvent; @@ -367,6 +373,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(); @@ -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 getRoundStateUpdateEvent(); public IEvent1 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() { } -- cgit v1.2.3