Kommentare
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@559 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
fd378778d1
commit
1823fb1610
5 changed files with 144 additions and 76 deletions
|
@ -43,7 +43,7 @@ public class GameOfferControl extends AbstractGameBeginControl {
|
||||||
.add(new IListener() {
|
.add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
List<PlayerSettings> players = gameData.getGameSettings()
|
gameData.getGameSettings()
|
||||||
.getPlayerList();
|
.getPlayerList();
|
||||||
if (checkPlayers()) {
|
if (checkPlayers()) {
|
||||||
startGame();
|
startGame();
|
||||||
|
|
|
@ -48,6 +48,8 @@ public class NetworkControl {
|
||||||
* user's login data
|
* user's login data
|
||||||
* @param connectionControl
|
* @param connectionControl
|
||||||
* current connection for events and messages
|
* current connection for events and messages
|
||||||
|
* @param saveControl
|
||||||
|
* save control if saving will ever be allowed
|
||||||
* @param view
|
* @param view
|
||||||
* for events and handlers
|
* for events and handlers
|
||||||
*/
|
*/
|
||||||
|
@ -79,6 +81,10 @@ public class NetworkControl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
addViewEventListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addViewEventListeners() {
|
||||||
connections.add(view.getQuitWarningPanel().getCancelEvent()
|
connections.add(view.getQuitWarningPanel().getCancelEvent()
|
||||||
.add(new IListener() {
|
.add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -165,7 +171,6 @@ public class NetworkControl {
|
||||||
if (ack) {
|
if (ack) {
|
||||||
createGameJoinControl();
|
createGameJoinControl();
|
||||||
} else {
|
} else {
|
||||||
// TODO Error message
|
|
||||||
view.showGameListPanel(true);
|
view.showGameListPanel(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -174,10 +179,12 @@ public class NetworkControl {
|
||||||
|
|
||||||
private void addConnectionSetupListeners(final LoginData loginData,
|
private void addConnectionSetupListeners(final LoginData loginData,
|
||||||
final IView view) {
|
final IView view) {
|
||||||
connections.add(connectionControl.getConnectedEvent().add(new IListener() {
|
connections.add(connectionControl.getConnectedEvent().add(
|
||||||
|
new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
view.getGameListPanel().setChannelName(loginData.getChannelName());
|
view.getGameListPanel().setChannelName(
|
||||||
|
loginData.getChannelName());
|
||||||
view.showConnectPanel(false);
|
view.showConnectPanel(false);
|
||||||
view.showGameListPanel(true);
|
view.showGameListPanel(true);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +331,8 @@ public class NetworkControl {
|
||||||
if (gameOfferControl != null) {
|
if (gameOfferControl != null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gameOfferControl = new GameOfferControl(connectionControl, settings, view);
|
gameOfferControl = new GameOfferControl(connectionControl, settings,
|
||||||
|
view);
|
||||||
gameOfferControl.getBackEvent().add(new IListener() {
|
gameOfferControl.getBackEvent().add(new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
|
@ -332,11 +340,12 @@ public class NetworkControl {
|
||||||
view.showGameListPanel(true);
|
view.showGameListPanel(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
gameOfferControl.getStartGameEvent().add(new IListener1<GameSettings>() {
|
gameOfferControl.getStartGameEvent().add(
|
||||||
|
new IListener1<GameSettings>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(GameSettings settings) {
|
public void handle(GameSettings settings) {
|
||||||
gameControl = new NetworkGameControl(settings, saveControl, view,
|
gameControl = new NetworkGameControl(settings,
|
||||||
connectionControl, true);
|
saveControl, view, connectionControl, true);
|
||||||
gameControl.startGame();
|
gameControl.startGame();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,12 +9,30 @@ import jrummikub.util.IListener;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
import jrummikub.view.IView.BottomPanelType;
|
import jrummikub.view.IView.BottomPanelType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class controlling network games
|
||||||
|
*/
|
||||||
public class NetworkGameControl extends GameControl {
|
public class NetworkGameControl extends GameControl {
|
||||||
private IConnectionControl connectionControl;
|
private IConnectionControl connectionControl;
|
||||||
private boolean host;
|
private boolean host;
|
||||||
|
|
||||||
public NetworkGameControl(GameSettings gameSettings, SaveControl saveControl,
|
/**
|
||||||
IView view, IConnectionControl connectionControl, boolean host) {
|
* Creates new network game control
|
||||||
|
*
|
||||||
|
* @param gameSettings
|
||||||
|
* current game settings
|
||||||
|
* @param saveControl
|
||||||
|
* if there should ever be saving in network mode
|
||||||
|
* @param view
|
||||||
|
* the view
|
||||||
|
* @param connectionControl
|
||||||
|
* the current connection
|
||||||
|
* @param host
|
||||||
|
* of the current game
|
||||||
|
*/
|
||||||
|
public NetworkGameControl(GameSettings gameSettings,
|
||||||
|
SaveControl saveControl, IView view,
|
||||||
|
IConnectionControl connectionControl, boolean host) {
|
||||||
super(gameSettings, saveControl, view);
|
super(gameSettings, saveControl, view);
|
||||||
|
|
||||||
this.connectionControl = connectionControl;
|
this.connectionControl = connectionControl;
|
||||||
|
@ -23,7 +41,8 @@ public class NetworkGameControl extends GameControl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void startRound() {
|
protected void startRound() {
|
||||||
connections.add(connectionControl.getRoundStartEvent().add(new IListener() {
|
connections.add(connectionControl.getRoundStartEvent().add(
|
||||||
|
new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
NetworkGameControl.super.startRound();
|
NetworkGameControl.super.startRound();
|
||||||
|
@ -42,7 +61,8 @@ public class NetworkGameControl extends GameControl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RoundControl createRoundControl(IRoundState roundState) {
|
protected RoundControl createRoundControl(IRoundState roundState) {
|
||||||
return new NetworkRoundControl(roundState, view, connectionControl, host);
|
return new NetworkRoundControl(roundState, view, connectionControl,
|
||||||
|
host);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -9,10 +9,25 @@ import jrummikub.util.IListener;
|
||||||
import jrummikub.util.IListener1;
|
import jrummikub.util.IListener1;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Round control for network games
|
||||||
|
*/
|
||||||
public class NetworkRoundControl extends RoundControl {
|
public class NetworkRoundControl extends RoundControl {
|
||||||
private IConnectionControl connectionControl;
|
private IConnectionControl connectionControl;
|
||||||
private boolean currentlyActive;
|
private boolean currentlyActive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new network round control
|
||||||
|
*
|
||||||
|
* @param roundState
|
||||||
|
* current round state
|
||||||
|
* @param view
|
||||||
|
* the view
|
||||||
|
* @param connectionControl
|
||||||
|
* connection control for the current connection
|
||||||
|
* @param startActive
|
||||||
|
* true for host
|
||||||
|
*/
|
||||||
public NetworkRoundControl(IRoundState roundState, IView view,
|
public NetworkRoundControl(IRoundState roundState, IView view,
|
||||||
final IConnectionControl connectionControl, boolean startActive) {
|
final IConnectionControl connectionControl, boolean startActive) {
|
||||||
super(roundState, view, false);
|
super(roundState, view, false);
|
||||||
|
@ -27,13 +42,15 @@ public class NetworkRoundControl extends RoundControl {
|
||||||
setRoundState(state);
|
setRoundState(state);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
connections.add(connectionControl.getTurnStartEvent().add(new IListener() {
|
connections.add(connectionControl.getTurnStartEvent().add(
|
||||||
|
new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
startTurn();
|
startTurn();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
connections.add(connectionControl.getNextPlayerEvent().add(new IListener() {
|
connections.add(connectionControl.getNextPlayerEvent().add(
|
||||||
|
new IListener() {
|
||||||
@Override
|
@Override
|
||||||
public void handle() {
|
public void handle() {
|
||||||
NetworkRoundControl.super.nextPlayer();
|
NetworkRoundControl.super.nextPlayer();
|
||||||
|
|
|
@ -38,8 +38,10 @@ public class NetworkRoundControlTest {
|
||||||
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
|
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
|
||||||
gameSettings.getPlayerList().add(
|
gameSettings.getPlayerList().add(
|
||||||
new PlayerSettings("Matthias", Color.YELLOW));
|
new PlayerSettings("Matthias", Color.YELLOW));
|
||||||
gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
|
gameSettings.getPlayerList().add(
|
||||||
gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
|
new PlayerSettings("Jannis", Color.GREEN));
|
||||||
|
gameSettings.getPlayerList().add(
|
||||||
|
new PlayerSettings("Bennet", Color.BLACK));
|
||||||
|
|
||||||
gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
|
gameSettings.getPlayerList().get(1).setType(Type.COMPUTER);
|
||||||
gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
|
gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
|
||||||
|
@ -49,9 +51,11 @@ public class NetworkRoundControlTest {
|
||||||
connectionControl = new MockConnectionControl();
|
connectionControl = new MockConnectionControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testHostRound() {
|
public void testHostRound() {
|
||||||
connectionControl.nickname = gameSettings.getPlayerList().get(0).getName();
|
connectionControl.nickname = gameSettings.getPlayerList().get(0)
|
||||||
|
.getName();
|
||||||
|
|
||||||
testRoundState = new RoundState(gameSettings, null);
|
testRoundState = new RoundState(gameSettings, null);
|
||||||
testRound = new NetworkRoundControl(testRoundState, view,
|
testRound = new NetworkRoundControl(testRoundState, view,
|
||||||
|
@ -67,8 +71,8 @@ public class NetworkRoundControlTest {
|
||||||
IPlayer player = testRoundState.getNthPlayer(i);
|
IPlayer player = testRoundState.getNthPlayer(i);
|
||||||
assertSame(gameSettings.getPlayerList().get(i),
|
assertSame(gameSettings.getPlayerList().get(i),
|
||||||
player.getPlayerSettings());
|
player.getPlayerSettings());
|
||||||
assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand()
|
assertEquals(gameSettings.getNumberOfStonesDealt(), player
|
||||||
.getSize());
|
.getHand().getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
@ -80,7 +84,8 @@ public class NetworkRoundControlTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(0),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertTrue(connectionControl.turnStarted);
|
assertTrue(connectionControl.turnStarted);
|
||||||
connectionControl.turnStarted = false;
|
connectionControl.turnStarted = false;
|
||||||
|
|
||||||
|
@ -95,7 +100,8 @@ public class NetworkRoundControlTest {
|
||||||
connectionControl.nextPlayer = false;
|
connectionControl.nextPlayer = false;
|
||||||
|
|
||||||
connectionControl.nextPlayerEvent.emit();
|
connectionControl.nextPlayerEvent.emit();
|
||||||
assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(1),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertTrue(connectionControl.turnStarted);
|
assertTrue(connectionControl.turnStarted);
|
||||||
connectionControl.turnStarted = false;
|
connectionControl.turnStarted = false;
|
||||||
|
|
||||||
|
@ -107,50 +113,59 @@ public class NetworkRoundControlTest {
|
||||||
connectionControl.nextPlayer = false;
|
connectionControl.nextPlayer = false;
|
||||||
|
|
||||||
connectionControl.nextPlayerEvent.emit();
|
connectionControl.nextPlayerEvent.emit();
|
||||||
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(2),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertTrue(connectionControl.turnStarted);
|
assertTrue(connectionControl.turnStarted);
|
||||||
connectionControl.turnStarted = false;
|
connectionControl.turnStarted = false;
|
||||||
|
|
||||||
connectionControl.turnStartEvent.emit();
|
connectionControl.turnStartEvent.emit();
|
||||||
assertFalse(connectionControl.turnEnded);
|
assertFalse(connectionControl.turnEnded);
|
||||||
|
|
||||||
connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo(
|
connectionControl.turnEndEvent.emit(testRoundState,
|
||||||
testRoundState.getTable(), null, Collections.<StoneSet> emptyList()));
|
new InvalidTurnInfo(testRoundState.getTable(), null,
|
||||||
|
Collections.<StoneSet> emptyList()));
|
||||||
|
|
||||||
assertFalse(connectionControl.nextPlayer);
|
assertFalse(connectionControl.nextPlayer);
|
||||||
|
|
||||||
connectionControl.nextPlayerEvent.emit();
|
connectionControl.nextPlayerEvent.emit();
|
||||||
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(3),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertFalse(connectionControl.turnStarted);
|
assertFalse(connectionControl.turnStarted);
|
||||||
|
|
||||||
connectionControl.turnStartEvent.emit();
|
connectionControl.turnStartEvent.emit();
|
||||||
assertFalse(connectionControl.turnEnded);
|
assertFalse(connectionControl.turnEnded);
|
||||||
|
|
||||||
connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo(
|
connectionControl.turnEndEvent.emit(testRoundState,
|
||||||
testRoundState.getTable(), null, Collections.<StoneSet> emptyList()));
|
new InvalidTurnInfo(testRoundState.getTable(), null,
|
||||||
|
Collections.<StoneSet> emptyList()));
|
||||||
|
|
||||||
assertFalse(connectionControl.nextPlayer);
|
assertFalse(connectionControl.nextPlayer);
|
||||||
|
|
||||||
connectionControl.nextPlayerEvent.emit();
|
connectionControl.nextPlayerEvent.emit();
|
||||||
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(0),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertFalse(connectionControl.turnStarted);
|
assertFalse(connectionControl.turnStarted);
|
||||||
|
|
||||||
connectionControl.turnStartEvent.emit();
|
connectionControl.turnStartEvent.emit();
|
||||||
assertFalse(connectionControl.turnEnded);
|
assertFalse(connectionControl.turnEnded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
@Test
|
@Test
|
||||||
public void testClientRound() {
|
public void testClientRound() {
|
||||||
connectionControl.nickname = gameSettings.getPlayerList().get(2).getName();
|
connectionControl.nickname = gameSettings.getPlayerList().get(2)
|
||||||
|
.getName();
|
||||||
|
|
||||||
testRoundState = new RoundState(gameSettings, null);
|
testRoundState = new RoundState(gameSettings, null);
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
IPlayer player = testRoundState.getNthPlayer(i);
|
IPlayer player = testRoundState.getNthPlayer(i);
|
||||||
|
|
||||||
player.getHand().drop(new Stone(StoneColor.RED), new Position(0, 0));
|
player.getHand()
|
||||||
|
.drop(new Stone(StoneColor.RED), new Position(0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
testRound = new NetworkRoundControl(null, view, connectionControl, false);
|
testRound = new NetworkRoundControl(null, view, connectionControl,
|
||||||
|
false);
|
||||||
|
|
||||||
connectionControl.turnStarted = false;
|
connectionControl.turnStarted = false;
|
||||||
connectionControl.turnEnded = false;
|
connectionControl.turnEnded = false;
|
||||||
|
@ -159,33 +174,38 @@ public class NetworkRoundControlTest {
|
||||||
|
|
||||||
connectionControl.roundStateUpdateEvent.emit(testRoundState);
|
connectionControl.roundStateUpdateEvent.emit(testRoundState);
|
||||||
|
|
||||||
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(0),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertFalse(connectionControl.turnStarted);
|
assertFalse(connectionControl.turnStarted);
|
||||||
|
|
||||||
connectionControl.turnStartEvent.emit();
|
connectionControl.turnStartEvent.emit();
|
||||||
assertFalse(connectionControl.turnEnded);
|
assertFalse(connectionControl.turnEnded);
|
||||||
|
|
||||||
connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo(
|
connectionControl.turnEndEvent.emit(testRoundState,
|
||||||
testRoundState.getTable(), null, Collections.<StoneSet> emptyList()));
|
new InvalidTurnInfo(testRoundState.getTable(), null,
|
||||||
|
Collections.<StoneSet> emptyList()));
|
||||||
|
|
||||||
assertFalse(connectionControl.turnEnded);
|
assertFalse(connectionControl.turnEnded);
|
||||||
|
|
||||||
assertFalse(connectionControl.nextPlayer);
|
assertFalse(connectionControl.nextPlayer);
|
||||||
|
|
||||||
connectionControl.nextPlayerEvent.emit();
|
connectionControl.nextPlayerEvent.emit();
|
||||||
assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(1),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertFalse(connectionControl.turnStarted);
|
assertFalse(connectionControl.turnStarted);
|
||||||
|
|
||||||
connectionControl.turnStartEvent.emit();
|
connectionControl.turnStartEvent.emit();
|
||||||
assertFalse(connectionControl.turnEnded);
|
assertFalse(connectionControl.turnEnded);
|
||||||
|
|
||||||
connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo(
|
connectionControl.turnEndEvent.emit(testRoundState,
|
||||||
testRoundState.getTable(), null, Collections.<StoneSet> emptyList()));
|
new InvalidTurnInfo(testRoundState.getTable(), null,
|
||||||
|
Collections.<StoneSet> emptyList()));
|
||||||
|
|
||||||
assertFalse(connectionControl.nextPlayer);
|
assertFalse(connectionControl.nextPlayer);
|
||||||
|
|
||||||
connectionControl.nextPlayerEvent.emit();
|
connectionControl.nextPlayerEvent.emit();
|
||||||
assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(2),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertFalse(connectionControl.turnStarted);
|
assertFalse(connectionControl.turnStarted);
|
||||||
|
|
||||||
connectionControl.turnStartEvent.emit();
|
connectionControl.turnStartEvent.emit();
|
||||||
|
@ -199,7 +219,8 @@ public class NetworkRoundControlTest {
|
||||||
connectionControl.nextPlayer = false;
|
connectionControl.nextPlayer = false;
|
||||||
|
|
||||||
connectionControl.nextPlayerEvent.emit();
|
connectionControl.nextPlayerEvent.emit();
|
||||||
assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(3),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertTrue(connectionControl.turnStarted);
|
assertTrue(connectionControl.turnStarted);
|
||||||
connectionControl.turnStarted = false;
|
connectionControl.turnStarted = false;
|
||||||
|
|
||||||
|
@ -211,7 +232,8 @@ public class NetworkRoundControlTest {
|
||||||
connectionControl.nextPlayer = false;
|
connectionControl.nextPlayer = false;
|
||||||
|
|
||||||
connectionControl.nextPlayerEvent.emit();
|
connectionControl.nextPlayerEvent.emit();
|
||||||
assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
|
assertSame(testRoundState.getNthPlayer(0),
|
||||||
|
testRoundState.getActivePlayer());
|
||||||
assertTrue(connectionControl.turnStarted);
|
assertTrue(connectionControl.turnStarted);
|
||||||
connectionControl.turnStarted = false;
|
connectionControl.turnStarted = false;
|
||||||
|
|
||||||
|
|
Reference in a new issue