Make NetworkRoundControl test work

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@496 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-06-19 23:19:01 +02:00
parent 890051a3e9
commit 9df5497276
6 changed files with 109 additions and 83 deletions

View file

@ -117,7 +117,20 @@ public class RoundControl {
}
}
private void prepareTurn() {
protected void prepareTurn() {
doPrepareTurn();
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
.getType() == HUMAN;
boolean oneHuman = roundState.getGameSettings().oneHuman();
boolean isAI = (turnControl instanceof AIControl);
if (isAI || (isHuman && oneHuman)) {
startTurn();
}
}
protected void doPrepareTurn() {
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
.getType() == HUMAN;
boolean oneHuman = roundState.getGameSettings().oneHuman();
@ -141,12 +154,6 @@ public class RoundControl {
turnControl = createTurnControl(roundState.getActivePlayer()
.getPlayerSettings());
boolean isAI = (turnControl instanceof AIControl);
if (isAI || (isHuman && oneHuman)) {
startTurn();
}
}
protected void startTurn() {
@ -217,7 +224,7 @@ public class RoundControl {
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
}
private void endOfTurn(ITable newTable) {
protected void endOfTurn(ITable newTable) {
boolean wasHuman = (turnControl instanceof HumanTurnControl);
boolean wasAI = (turnControl instanceof AIControl);

View file

@ -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<IRoundState>() {
@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);
}
}

View file

@ -97,7 +97,11 @@ public abstract class AbstractTurnControl implements ITurnControl {
}
protected void cleanUp() {
timer.stopTimer();
if (timer != null) {
timer.stopTimer();
}
started = true;
for (Connection c : connections) {
c.remove();
}

View file

@ -90,7 +90,6 @@ public class HumanTurnControl extends AbstractTurnControl {
connections.add(view.getPlayerPanel().getEndTurnEvent()
.add(new IListener() {
@Override
public void handle() {
endOfTurn(false);