Add client side to NetworkRoundControl test and implementation
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@498 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
ec54bde90a
commit
fcf33eb280
3 changed files with 86 additions and 9 deletions
|
@ -81,7 +81,10 @@ public class RoundControl {
|
|||
* Begin the round
|
||||
*/
|
||||
public void startRound() {
|
||||
deal();
|
||||
if (roundState != null) {
|
||||
deal();
|
||||
}
|
||||
|
||||
continueRound();
|
||||
}
|
||||
|
||||
|
@ -103,7 +106,9 @@ public class RoundControl {
|
|||
}
|
||||
}));
|
||||
|
||||
prepareTurn();
|
||||
if (roundState != null) {
|
||||
prepareTurn();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -117,11 +122,16 @@ public class RoundControl {
|
|||
}
|
||||
}
|
||||
|
||||
protected void setRoundState(IRoundState state) {
|
||||
roundState = state;
|
||||
roundStateUpdateEvent.emit(state);
|
||||
}
|
||||
|
||||
protected void prepareTurn() {
|
||||
doPrepareTurn();
|
||||
|
||||
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
|
||||
.getType() == HUMAN;
|
||||
.getType() == HUMAN;
|
||||
boolean oneHuman = roundState.getGameSettings().oneHuman();
|
||||
boolean isAI = (turnControl instanceof AIControl);
|
||||
|
||||
|
@ -157,6 +167,10 @@ public class RoundControl {
|
|||
}
|
||||
|
||||
protected void startTurn() {
|
||||
if (turnControl == null) {
|
||||
doPrepareTurn();
|
||||
}
|
||||
|
||||
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
|
||||
.getType() == HUMAN;
|
||||
|
||||
|
|
|
@ -23,7 +23,8 @@ public class NetworkRoundControl extends RoundControl {
|
|||
new IListener1<IRoundState>() {
|
||||
@Override
|
||||
public void handle(IRoundState state) {
|
||||
NetworkRoundControl.this.roundState = state;
|
||||
setRoundState(state);
|
||||
|
||||
startTurn();
|
||||
}
|
||||
}));
|
||||
|
|
|
@ -9,8 +9,10 @@ import jrummikub.model.GameSettings;
|
|||
import jrummikub.model.IPlayer;
|
||||
import jrummikub.model.PlayerSettings;
|
||||
import jrummikub.model.PlayerSettings.Type;
|
||||
import jrummikub.model.Position;
|
||||
import jrummikub.model.RoundState;
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.model.StoneColor;
|
||||
import jrummikub.view.MockView;
|
||||
|
||||
import org.junit.Before;
|
||||
|
@ -36,17 +38,16 @@ public class NetworkRoundControlTest {
|
|||
gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
|
||||
gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
|
||||
|
||||
gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
|
||||
gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
|
||||
gameSettings.getPlayerList().get(3).setType(Type.COMPUTER);
|
||||
testRoundState = new RoundState(gameSettings);
|
||||
|
||||
view = new MockView();
|
||||
connectionControl = new MockConnectionControl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHostRound() {
|
||||
gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
|
||||
gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
|
||||
gameSettings.getPlayerList().get(3).setType(Type.COMPUTER);
|
||||
testRoundState = new RoundState(gameSettings);
|
||||
testRound = new NetworkRoundControl(testRoundState, view,
|
||||
connectionControl, true);
|
||||
|
||||
|
@ -115,4 +116,65 @@ public class NetworkRoundControlTest {
|
|||
connectionControl.turnStartEvent.emit(testRoundState);
|
||||
assertFalse(connectionControl.turnEnded);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientRound() {
|
||||
gameSettings.getPlayerList().get(0).setType(Type.NETWORK);
|
||||
gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
|
||||
gameSettings.getPlayerList().get(3).setType(Type.COMPUTER);
|
||||
testRoundState = new RoundState(gameSettings);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
IPlayer player = testRoundState.getNthPlayer(i);
|
||||
|
||||
player.getHand().drop(new Stone(StoneColor.RED), new Position(0, 0));
|
||||
}
|
||||
|
||||
testRound = new NetworkRoundControl(null, view, connectionControl, false);
|
||||
|
||||
connectionControl.turnStarted = false;
|
||||
connectionControl.turnEnded = false;
|
||||
|
||||
testRound.startRound();
|
||||
|
||||
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
||||
assertFalse(connectionControl.turnStarted);
|
||||
|
||||
connectionControl.turnStartEvent.emit(testRoundState);
|
||||
assertFalse(connectionControl.turnEnded);
|
||||
|
||||
connectionControl.turnEndEvent.emit(testRoundState.getTable());
|
||||
|
||||
assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer());
|
||||
assertFalse(connectionControl.turnStarted);
|
||||
|
||||
connectionControl.turnStartEvent.emit(testRoundState);
|
||||
assertFalse(connectionControl.turnEnded);
|
||||
|
||||
connectionControl.turnEndEvent.emit(testRoundState.getTable());
|
||||
|
||||
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
|
||||
assertFalse(connectionControl.turnStarted);
|
||||
|
||||
connectionControl.turnStartEvent.emit(testRoundState);
|
||||
|
||||
assertFalse(connectionControl.turnEnded);
|
||||
view.playerPanel.endTurnEvent.emit();
|
||||
assertTrue(connectionControl.turnEnded);
|
||||
connectionControl.turnEnded = false;
|
||||
|
||||
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
|
||||
assertTrue(connectionControl.turnStarted);
|
||||
connectionControl.turnStarted = false;
|
||||
|
||||
connectionControl.turnStartEvent.emit(testRoundState);
|
||||
assertTrue(connectionControl.turnEnded);
|
||||
connectionControl.turnEnded = false;
|
||||
|
||||
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
||||
assertTrue(connectionControl.turnStarted);
|
||||
connectionControl.turnStarted = false;
|
||||
|
||||
connectionControl.turnStartEvent.emit(testRoundState);
|
||||
assertFalse(connectionControl.turnEnded);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue