From 9df549727672e8df768d46e3ef1fb0c7957f0f89 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sun, 19 Jun 2011 23:19:01 +0200 Subject: Make NetworkRoundControl test work git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@496 72836036-5685-4462-b002-a69064685172 --- .../control/network/NetworkRoundControl.java | 44 +++++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'src/jrummikub/control/network') 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() { + @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); } } -- cgit v1.2.3