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:
parent
890051a3e9
commit
9df5497276
6 changed files with 109 additions and 83 deletions
|
@ -53,6 +53,10 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
public GameData joinedGame;
|
public GameData joinedGame;
|
||||||
/** */
|
/** */
|
||||||
public Color playerColor;
|
public Color playerColor;
|
||||||
|
/** */
|
||||||
|
public boolean turnStarted;
|
||||||
|
/** */
|
||||||
|
public boolean turnEnded;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNickname() {
|
public String getNickname() {
|
||||||
|
@ -191,13 +195,11 @@ public class MockConnectionControl implements IConnectionControl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void endTurn(ITable table) {
|
public void endTurn(ITable table) {
|
||||||
// TODO Auto-generated method stub
|
turnEnded = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void startTurn(IRoundState state) {
|
public void startTurn(IRoundState state) {
|
||||||
// TODO Auto-generated method stub
|
turnStarted = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
|
||||||
.getType() == HUMAN;
|
.getType() == HUMAN;
|
||||||
boolean oneHuman = roundState.getGameSettings().oneHuman();
|
boolean oneHuman = roundState.getGameSettings().oneHuman();
|
||||||
|
@ -141,12 +154,6 @@ public class RoundControl {
|
||||||
|
|
||||||
turnControl = createTurnControl(roundState.getActivePlayer()
|
turnControl = createTurnControl(roundState.getActivePlayer()
|
||||||
.getPlayerSettings());
|
.getPlayerSettings());
|
||||||
|
|
||||||
boolean isAI = (turnControl instanceof AIControl);
|
|
||||||
|
|
||||||
if (isAI || (isHuman && oneHuman)) {
|
|
||||||
startTurn();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void startTurn() {
|
protected void startTurn() {
|
||||||
|
@ -217,7 +224,7 @@ public class RoundControl {
|
||||||
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
|
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void endOfTurn(ITable newTable) {
|
protected void endOfTurn(ITable newTable) {
|
||||||
boolean wasHuman = (turnControl instanceof HumanTurnControl);
|
boolean wasHuman = (turnControl instanceof HumanTurnControl);
|
||||||
boolean wasAI = (turnControl instanceof AIControl);
|
boolean wasAI = (turnControl instanceof AIControl);
|
||||||
|
|
||||||
|
|
|
@ -12,11 +12,21 @@ public class NetworkRoundControl extends RoundControl {
|
||||||
private IConnectionControl connectionControl;
|
private IConnectionControl connectionControl;
|
||||||
private boolean currentlyActive;
|
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);
|
super(roundState, view);
|
||||||
|
|
||||||
this.connectionControl = connectionControl;
|
this.connectionControl = connectionControl;
|
||||||
currentlyActive = startActive;
|
currentlyActive = startActive;
|
||||||
|
|
||||||
|
connections.add(connectionControl.getTurnStartEvent().add(
|
||||||
|
new IListener1<IRoundState>() {
|
||||||
|
@Override
|
||||||
|
public void handle(IRoundState state) {
|
||||||
|
NetworkRoundControl.this.roundState = state;
|
||||||
|
startTurn();
|
||||||
|
}
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,8 +58,22 @@ public class NetworkRoundControl extends RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startTurn() {
|
protected void prepareTurn() {
|
||||||
|
boolean wasActive = currentlyActive;
|
||||||
|
|
||||||
|
doPrepareTurn();
|
||||||
|
|
||||||
|
if (wasActive) {
|
||||||
connectionControl.startTurn(roundState);
|
connectionControl.startTurn(roundState);
|
||||||
super.startTurn();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void endOfTurn(ITable newTable) {
|
||||||
|
if (currentlyActive) {
|
||||||
|
connectionControl.endTurn(newTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.endOfTurn(newTable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,11 @@ public abstract class AbstractTurnControl implements ITurnControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void cleanUp() {
|
protected void cleanUp() {
|
||||||
|
if (timer != null) {
|
||||||
timer.stopTimer();
|
timer.stopTimer();
|
||||||
|
}
|
||||||
|
started = true;
|
||||||
|
|
||||||
for (Connection c : connections) {
|
for (Connection c : connections) {
|
||||||
c.remove();
|
c.remove();
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,6 @@ public class HumanTurnControl extends AbstractTurnControl {
|
||||||
|
|
||||||
connections.add(view.getPlayerPanel().getEndTurnEvent()
|
connections.add(view.getPlayerPanel().getEndTurnEvent()
|
||||||
.add(new IListener() {
|
.add(new IListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
endOfTurn(false);
|
endOfTurn(false);
|
||||||
|
|
|
@ -7,13 +7,10 @@ import java.awt.Color;
|
||||||
import jrummikub.control.turn.AIControl;
|
import jrummikub.control.turn.AIControl;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.IPlayer;
|
import jrummikub.model.IPlayer;
|
||||||
import jrummikub.model.IRoundState;
|
|
||||||
import jrummikub.model.ITable;
|
|
||||||
import jrummikub.model.PlayerSettings;
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.model.PlayerSettings.Type;
|
import jrummikub.model.PlayerSettings.Type;
|
||||||
import jrummikub.model.RoundState;
|
import jrummikub.model.RoundState;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.util.IListener1;
|
|
||||||
import jrummikub.view.MockView;
|
import jrummikub.view.MockView;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -27,9 +24,6 @@ public class NetworkRoundControlTest {
|
||||||
|
|
||||||
private GameSettings gameSettings;
|
private GameSettings gameSettings;
|
||||||
|
|
||||||
private boolean turnStarted;
|
|
||||||
private boolean turnEnded;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
AIControl.useBackgroundThread = false;
|
AIControl.useBackgroundThread = false;
|
||||||
|
@ -53,38 +47,22 @@ public class NetworkRoundControlTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHostRound() {
|
public void testHostRound() {
|
||||||
testRound = new NetworkRoundControl(testRoundState, view, connectionControl, true);
|
testRound = new NetworkRoundControl(testRoundState, view,
|
||||||
|
connectionControl, true);
|
||||||
|
|
||||||
connectionControl.getTurnStartEvent().add(new IListener1<IRoundState>() {
|
connectionControl.turnStarted = false;
|
||||||
@Override
|
connectionControl.turnEnded = false;
|
||||||
public void handle(IRoundState roundState) {
|
|
||||||
assertSame(testRoundState, roundState);
|
|
||||||
|
|
||||||
turnStarted = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
connectionControl.getTurnEndEvent().add(new IListener1<ITable>() {
|
|
||||||
@Override
|
|
||||||
public void handle(ITable table) {
|
|
||||||
turnEnded = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
turnStarted = false;
|
|
||||||
turnEnded = false;
|
|
||||||
|
|
||||||
testRound.startRound();
|
testRound.startRound();
|
||||||
assertTrue(turnStarted);
|
|
||||||
turnStarted = false;
|
|
||||||
|
|
||||||
assertEquals(4, testRoundState.getPlayerCount());
|
assertEquals(4, testRoundState.getPlayerCount());
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
IPlayer player = testRoundState.getNthPlayer(i);
|
IPlayer player = testRoundState.getNthPlayer(i);
|
||||||
assertSame(gameSettings.getPlayerList().get(i), player.getPlayerSettings());
|
assertSame(gameSettings.getPlayerList().get(i),
|
||||||
assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand().getSize());
|
player.getPlayerSettings());
|
||||||
|
assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand()
|
||||||
|
.getSize());
|
||||||
}
|
}
|
||||||
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
IPlayer player = testRoundState.getNthPlayer(i);
|
IPlayer player = testRoundState.getNthPlayer(i);
|
||||||
|
@ -95,34 +73,46 @@ public class NetworkRoundControlTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertFalse(turnEnded);
|
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
||||||
|
assertTrue(connectionControl.turnStarted);
|
||||||
|
connectionControl.turnStarted = false;
|
||||||
|
|
||||||
|
connectionControl.turnStartEvent.emit(testRoundState);
|
||||||
|
|
||||||
|
assertFalse(connectionControl.turnEnded);
|
||||||
view.playerPanel.endTurnEvent.emit();
|
view.playerPanel.endTurnEvent.emit();
|
||||||
assertTrue(turnEnded);
|
assertTrue(connectionControl.turnEnded);
|
||||||
turnEnded = false;
|
connectionControl.turnEnded = false;
|
||||||
turnStarted = false;
|
|
||||||
|
assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer());
|
||||||
|
assertTrue(connectionControl.turnStarted);
|
||||||
|
connectionControl.turnStarted = false;
|
||||||
|
|
||||||
|
connectionControl.turnStartEvent.emit(testRoundState);
|
||||||
|
assertTrue(connectionControl.turnEnded);
|
||||||
|
connectionControl.turnEnded = false;
|
||||||
|
|
||||||
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
|
||||||
|
assertTrue(connectionControl.turnStarted);
|
||||||
|
connectionControl.turnStarted = false;
|
||||||
|
|
||||||
connectionControl.turnStartEvent.emit(testRoundState);
|
connectionControl.turnStartEvent.emit(testRoundState);
|
||||||
assertTrue(turnStarted);
|
assertFalse(connectionControl.turnEnded);
|
||||||
turnStarted = false;
|
|
||||||
|
|
||||||
assertFalse(turnEnded);
|
|
||||||
connectionControl.turnEndEvent.emit(testRoundState.getTable());
|
connectionControl.turnEndEvent.emit(testRoundState.getTable());
|
||||||
assertTrue(turnEnded);
|
|
||||||
turnEnded = false;
|
|
||||||
|
|
||||||
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
|
||||||
|
assertFalse(connectionControl.turnStarted);
|
||||||
|
|
||||||
connectionControl.turnStartEvent.emit(testRoundState);
|
connectionControl.turnStartEvent.emit(testRoundState);
|
||||||
assertTrue(turnStarted);
|
assertFalse(connectionControl.turnEnded);
|
||||||
turnStarted = false;
|
|
||||||
|
|
||||||
assertFalse(turnEnded);
|
|
||||||
connectionControl.turnEndEvent.emit(testRoundState.getTable());
|
connectionControl.turnEndEvent.emit(testRoundState.getTable());
|
||||||
assertTrue(turnEnded);
|
|
||||||
turnEnded = false;
|
|
||||||
|
|
||||||
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
||||||
|
assertFalse(connectionControl.turnStarted);
|
||||||
|
|
||||||
|
connectionControl.turnStartEvent.emit(testRoundState);
|
||||||
|
assertFalse(connectionControl.turnEnded);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue