diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-21 00:04:16 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-21 00:04:16 +0200 |
commit | f5cff88ec9177b23dc8979aa9645a427a78c6f46 (patch) | |
tree | 5192fc950c594b9772bf28b1e8e3d712817c3b09 /src/jrummikub/control/network | |
parent | 1ba3c9758394f551aa913df52852c19e7e6c6187 (diff) | |
download | JRummikub-f5cff88ec9177b23dc8979aa9645a427a78c6f46.tar JRummikub-f5cff88ec9177b23dc8979aa9645a427a78c6f46.zip |
Major refactoring of RoundControl and TurnControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@516 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/network')
4 files changed, 49 insertions, 61 deletions
diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index 76b430a..4ed160a 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -6,19 +6,17 @@ import java.util.UUID; import javax.swing.SwingUtilities; +import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.model.GameSettings; -import jrummikub.model.IHand; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.Event2; -import jrummikub.util.Event3; import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; -import jrummikub.util.IEvent3; import jrummikub.util.LoginData; import jrummikub.view.LoginError; @@ -48,26 +46,20 @@ public class ConnectionControl implements IConnectionControl { private static class TurnEndData implements Serializable { private static final long serialVersionUID = -3800572117130220737L; - private IHand oldHand; - private ITable oldTable; - private ITable newTable; + private IRoundState roundState; + private InvalidTurnInfo invalidTurnInfo; - TurnEndData(IHand oldHand, ITable oldTable, ITable newTable) { - this.oldHand = oldHand; - this.oldTable = oldTable; - this.newTable = newTable; + TurnEndData(IRoundState roundState, InvalidTurnInfo invalidTurnInfo) { + this.roundState = roundState; + this.invalidTurnInfo = invalidTurnInfo; } - IHand getOldHand() { - return oldHand; + IRoundState getRoundState() { + return roundState; } - ITable getOldTable() { - return oldTable; - } - - ITable getNewTable() { - return newTable; + InvalidTurnInfo getInvalidTurnInfo() { + return invalidTurnInfo; } } @@ -95,8 +87,8 @@ public class ConnectionControl implements IConnectionControl { private Event roundStartEvent = new Event(); private Event1<ITable> tableUpdateEvent = new Event1<ITable>(); - private Event3<IHand, ITable, ITable> turnEndEvent = new Event3<IHand, ITable, ITable>(); - private Event1<IRoundState> turnStartEvent = new Event1<IRoundState>(); + private Event2<IRoundState, InvalidTurnInfo> turnEndEvent = new Event2<IRoundState, InvalidTurnInfo>(); + private Event turnStartEvent = new Event(); private GameData currentGame; @@ -195,12 +187,12 @@ public class ConnectionControl implements IConnectionControl { } @Override - public IEvent3<IHand, ITable, ITable> getTurnEndEvent() { + public IEvent2<IRoundState, InvalidTurnInfo> getTurnEndEvent() { return turnEndEvent; } @Override - public IEvent1<IRoundState> getTurnStartEvent() { + public IEvent getTurnStartEvent() { return turnStartEvent; } @@ -334,29 +326,28 @@ public class ConnectionControl implements IConnectionControl { } @Override - public void endTurn(final IHand oldHand, final ITable oldTable, - final ITable newTable) { + public void endTurn(final IRoundState state, + final InvalidTurnInfo invalidTurnInfo) { final UUID uuid = currentGame.getGameID(); run(new SendRunner() { @Override protected void addData(DefaultPacketExtension extension) { extension.setValue("messageType", "turn_end"); extension.setValue("uuid", uuid.toString()); - extension.setValue("data", Base64.encodeObject(new TurnEndData(oldHand, - oldTable, newTable), Base64.GZIP)); + extension.setValue("data", Base64.encodeObject(new TurnEndData(state, + invalidTurnInfo), Base64.GZIP)); } }); } @Override - public void startTurn(final IRoundState state) { + public void startTurn() { final UUID uuid = currentGame.getGameID(); run(new SendRunner() { @Override protected void addData(DefaultPacketExtension extension) { extension.setValue("messageType", "turn_start"); extension.setValue("uuid", uuid.toString()); - extension.setValue("state", Base64.encodeObject(state, Base64.GZIP)); } }); } @@ -474,11 +465,9 @@ public class ConnectionControl implements IConnectionControl { } else if (messageType.equals("turn_end")) { TurnEndData data = (TurnEndData) Base64.decodeToObject(extension .getValue("data")); - turnEndEvent.emit(data.getOldHand(), data.getOldTable(), - data.getNewTable()); + turnEndEvent.emit(data.getRoundState(), data.getInvalidTurnInfo()); } else if (messageType.equals("turn_start")) { - turnStartEvent.emit((IRoundState) Base64.decodeToObject(extension - .getValue("state"))); + turnStartEvent.emit(); } else { System.err.println("Received unrecognized message of type '" + messageType + "'"); diff --git a/src/jrummikub/control/network/IConnectionControl.java b/src/jrummikub/control/network/IConnectionControl.java index 38bc05c..b93748c 100644 --- a/src/jrummikub/control/network/IConnectionControl.java +++ b/src/jrummikub/control/network/IConnectionControl.java @@ -3,14 +3,13 @@ package jrummikub.control.network; import java.awt.Color; import java.util.UUID; -import jrummikub.model.IHand; +import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; -import jrummikub.util.IEvent3; import jrummikub.view.LoginError; interface IConnectionControl { @@ -43,9 +42,9 @@ interface IConnectionControl { public IEvent1<ITable> getTableUpdateEvent(); - public IEvent3<IHand, ITable, ITable> getTurnEndEvent(); + public IEvent2<IRoundState, InvalidTurnInfo> getTurnEndEvent(); - public IEvent1<IRoundState> getTurnStartEvent(); + public IEvent getTurnStartEvent(); public void offerGame(GameData data); @@ -69,7 +68,8 @@ interface IConnectionControl { public void updateTable(ITable table); - public void endTurn(IHand oldHand, ITable oldTable, ITable newTable); + public void endTurn(IRoundState state, InvalidTurnInfo invalidTurnInfo); + + public void startTurn(); - public void startTurn(IRoundState state); }
\ No newline at end of file diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java index 81820e7..64faebb 100644 --- a/src/jrummikub/control/network/NetworkRoundControl.java +++ b/src/jrummikub/control/network/NetworkRoundControl.java @@ -2,10 +2,10 @@ package jrummikub.control.network; import jrummikub.control.RoundControl; import jrummikub.control.turn.ITurnControl; -import jrummikub.model.IHand; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.model.PlayerSettings.Type; +import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.view.IView; @@ -20,17 +20,12 @@ public class NetworkRoundControl extends RoundControl { this.connectionControl = connectionControl; currentlyActive = startActive; - connections.add(connectionControl.getTurnStartEvent().add( - new IListener1<IRoundState>() { - @Override - public void handle(IRoundState state) { - NetworkControl.fixGameSettings(state.getGameSettings(), - connectionControl.getNickname()); - setRoundState(state); - - startTurn(); - } - })); + connections.add(connectionControl.getTurnStartEvent().add(new IListener() { + @Override + public void handle() { + startTurn(); + } + })); } @Override @@ -68,16 +63,16 @@ public class NetworkRoundControl extends RoundControl { doPrepareTurn(); if (wasActive) { - connectionControl.startTurn(roundState); + connectionControl.startTurn(); } } @Override - protected void endOfTurn(IHand oldHand, ITable oldTable, ITable newTable) { + protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) { if (currentlyActive) { - connectionControl.endTurn(oldHand, oldTable, newTable); + connectionControl.endTurn(roundState, invalidTurnInfo); } - super.endOfTurn(oldHand, oldTable, newTable); + super.endOfTurn(invalidTurnInfo); } } diff --git a/src/jrummikub/control/network/NetworkTurnControl.java b/src/jrummikub/control/network/NetworkTurnControl.java index 57851a2..7b0bcbb 100644 --- a/src/jrummikub/control/network/NetworkTurnControl.java +++ b/src/jrummikub/control/network/NetworkTurnControl.java @@ -1,13 +1,13 @@ package jrummikub.control.network; +import jrummikub.control.RoundControl.InvalidTurnInfo; import jrummikub.control.turn.AbstractTurnControl; -import jrummikub.model.IHand; import jrummikub.model.IRoundState; import jrummikub.model.ITable; import jrummikub.util.Event1; import jrummikub.util.IEvent1; import jrummikub.util.IListener1; -import jrummikub.util.IListener3; +import jrummikub.util.IListener2; public class NetworkTurnControl extends AbstractTurnControl { private IConnectionControl connectionControl; @@ -31,20 +31,24 @@ public class NetworkTurnControl extends AbstractTurnControl { } })); connections.add(connectionControl.getTurnEndEvent().add( - new IListener3<IHand, ITable, ITable>() { + new IListener2<IRoundState, InvalidTurnInfo>() { @Override - public void handle(IHand oldHand, ITable oldTable, ITable newTable) { - endOfTurn(oldHand, oldTable, newTable); + public void handle(IRoundState state, + InvalidTurnInfo invalidTurnInfo) { + NetworkControl.fixGameSettings(state.getGameSettings(), + connectionControl.getNickname()); + + endOfTurn(state, invalidTurnInfo); } })); timer.startTimer(); } - private void endOfTurn(IHand oldHand, ITable oldTable, ITable newTable) { + private void endOfTurn(IRoundState roundState, InvalidTurnInfo invalidTurnInfo) { cleanUp(); - endOfTurnEvent.emit(oldHand, oldTable, newTable); + endOfTurnEvent.emit(roundState, invalidTurnInfo); } @Override |