summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-06-22 00:12:04 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-06-22 00:12:04 +0200
commit1823fb1610fde82a1c3ae60edf9ea187cf18e54c (patch)
tree0a09d02e8631e7d9bfea0dbcd5151516ba6b76c0
parentfd378778d17563d4a72b6970ab1639b809c43c47 (diff)
downloadJRummikub-1823fb1610fde82a1c3ae60edf9ea187cf18e54c.tar
JRummikub-1823fb1610fde82a1c3ae60edf9ea187cf18e54c.zip
Kommentare
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@559 72836036-5685-4462-b002-a69064685172
-rw-r--r--src/jrummikub/control/network/GameOfferControl.java2
-rw-r--r--src/jrummikub/control/network/NetworkControl.java53
-rw-r--r--src/jrummikub/control/network/NetworkGameControl.java38
-rw-r--r--src/jrummikub/control/network/NetworkRoundControl.java53
-rw-r--r--test/jrummikub/control/network/NetworkRoundControlTest.java74
5 files changed, 144 insertions, 76 deletions
diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java
index c697647..52b2d0e 100644
--- a/src/jrummikub/control/network/GameOfferControl.java
+++ b/src/jrummikub/control/network/GameOfferControl.java
@@ -43,7 +43,7 @@ public class GameOfferControl extends AbstractGameBeginControl {
.add(new IListener() {
@Override
public void handle() {
- List<PlayerSettings> players = gameData.getGameSettings()
+ gameData.getGameSettings()
.getPlayerList();
if (checkPlayers()) {
startGame();
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index a9b889f..ce46a0f 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -45,11 +45,13 @@ public class NetworkControl {
* Creates a new network control
*
* @param loginData
- * user's login data
+ * user's login data
* @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
- * for events and handlers
+ * for events and handlers
*/
public NetworkControl(final LoginData loginData,
IConnectionControl connectionControl, SaveControl saveControl,
@@ -79,6 +81,10 @@ public class NetworkControl {
}
}
}));
+ addViewEventListeners();
+ }
+
+ private void addViewEventListeners() {
connections.add(view.getQuitWarningPanel().getCancelEvent()
.add(new IListener() {
@Override
@@ -126,7 +132,7 @@ public class NetworkControl {
* Adds the listeners for connection control events
*
* @param view
- * view for events
+ * view for events
*/
public void addConnectionControlListeners(final IView view) {
connections.add(connectionControl.getGameOfferEvent().add(
@@ -165,7 +171,6 @@ public class NetworkControl {
if (ack) {
createGameJoinControl();
} else {
- // TODO Error message
view.showGameListPanel(true);
}
}
@@ -174,14 +179,16 @@ public class NetworkControl {
private void addConnectionSetupListeners(final LoginData loginData,
final IView view) {
- connections.add(connectionControl.getConnectedEvent().add(new IListener() {
- @Override
- public void handle() {
- view.getGameListPanel().setChannelName(loginData.getChannelName());
- view.showConnectPanel(false);
- view.showGameListPanel(true);
- }
- }));
+ connections.add(connectionControl.getConnectedEvent().add(
+ new IListener() {
+ @Override
+ public void handle() {
+ view.getGameListPanel().setChannelName(
+ loginData.getChannelName());
+ view.showConnectPanel(false);
+ view.showGameListPanel(true);
+ }
+ }));
connections.add(connectionControl.getConnectionFailedEvent().add(
new IListener1<LoginError>() {
@@ -324,7 +331,8 @@ public class NetworkControl {
if (gameOfferControl != null) {
return;
}
- gameOfferControl = new GameOfferControl(connectionControl, settings, view);
+ gameOfferControl = new GameOfferControl(connectionControl, settings,
+ view);
gameOfferControl.getBackEvent().add(new IListener() {
@Override
public void handle() {
@@ -332,14 +340,15 @@ public class NetworkControl {
view.showGameListPanel(true);
}
});
- gameOfferControl.getStartGameEvent().add(new IListener1<GameSettings>() {
- @Override
- public void handle(GameSettings settings) {
- gameControl = new NetworkGameControl(settings, saveControl, view,
- connectionControl, true);
- gameControl.startGame();
- }
- });
+ gameOfferControl.getStartGameEvent().add(
+ new IListener1<GameSettings>() {
+ @Override
+ public void handle(GameSettings settings) {
+ gameControl = new NetworkGameControl(settings,
+ saveControl, view, connectionControl, true);
+ gameControl.startGame();
+ }
+ });
gameOfferControl.startGameOffer();
}
diff --git a/src/jrummikub/control/network/NetworkGameControl.java b/src/jrummikub/control/network/NetworkGameControl.java
index 9451876..d053e92 100644
--- a/src/jrummikub/control/network/NetworkGameControl.java
+++ b/src/jrummikub/control/network/NetworkGameControl.java
@@ -9,12 +9,30 @@ import jrummikub.util.IListener;
import jrummikub.view.IView;
import jrummikub.view.IView.BottomPanelType;
+/**
+ * Class controlling network games
+ */
public class NetworkGameControl extends GameControl {
private IConnectionControl connectionControl;
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);
this.connectionControl = connectionControl;
@@ -23,12 +41,13 @@ public class NetworkGameControl extends GameControl {
@Override
protected void startRound() {
- connections.add(connectionControl.getRoundStartEvent().add(new IListener() {
- @Override
- public void handle() {
- NetworkGameControl.super.startRound();
- }
- }));
+ connections.add(connectionControl.getRoundStartEvent().add(
+ new IListener() {
+ @Override
+ public void handle() {
+ NetworkGameControl.super.startRound();
+ }
+ }));
if (host) {
connectionControl.startRound();
@@ -42,7 +61,8 @@ public class NetworkGameControl extends GameControl {
@Override
protected RoundControl createRoundControl(IRoundState roundState) {
- return new NetworkRoundControl(roundState, view, connectionControl, host);
+ return new NetworkRoundControl(roundState, view, connectionControl,
+ host);
}
@Override
diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java
index 20a4c28..af7f675 100644
--- a/src/jrummikub/control/network/NetworkRoundControl.java
+++ b/src/jrummikub/control/network/NetworkRoundControl.java
@@ -9,10 +9,25 @@ import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.view.IView;
+/**
+ * Round control for network games
+ */
public class NetworkRoundControl extends RoundControl {
private IConnectionControl connectionControl;
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,
final IConnectionControl connectionControl, boolean startActive) {
super(roundState, view, false);
@@ -27,18 +42,20 @@ public class NetworkRoundControl extends RoundControl {
setRoundState(state);
}
}));
- connections.add(connectionControl.getTurnStartEvent().add(new IListener() {
- @Override
- public void handle() {
- startTurn();
- }
- }));
- connections.add(connectionControl.getNextPlayerEvent().add(new IListener() {
- @Override
- public void handle() {
- NetworkRoundControl.super.nextPlayer();
- }
- }));
+ connections.add(connectionControl.getTurnStartEvent().add(
+ new IListener() {
+ @Override
+ public void handle() {
+ startTurn();
+ }
+ }));
+ connections.add(connectionControl.getNextPlayerEvent().add(
+ new IListener() {
+ @Override
+ public void handle() {
+ NetworkRoundControl.super.nextPlayer();
+ }
+ }));
}
@Override
@@ -54,12 +71,12 @@ public class NetworkRoundControl extends RoundControl {
@Override
protected ITurnControl createTurnControl(Type type) {
switch (type) {
- case HUMAN:
- currentlyActive = true;
- break;
- case NETWORK:
- currentlyActive = false;
- break;
+ case HUMAN:
+ currentlyActive = true;
+ break;
+ case NETWORK:
+ currentlyActive = false;
+ break;
}
if (!currentlyActive) {
diff --git a/test/jrummikub/control/network/NetworkRoundControlTest.java b/test/jrummikub/control/network/NetworkRoundControlTest.java
index d8300d2..22daa44 100644
--- a/test/jrummikub/control/network/NetworkRoundControlTest.java
+++ b/test/jrummikub/control/network/NetworkRoundControlTest.java
@@ -38,8 +38,10 @@ public class NetworkRoundControlTest {
gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
gameSettings.getPlayerList().add(
new PlayerSettings("Matthias", Color.YELLOW));
- gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
- gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
+ 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);
@@ -49,9 +51,11 @@ public class NetworkRoundControlTest {
connectionControl = new MockConnectionControl();
}
+ /** */
@Test
public void testHostRound() {
- connectionControl.nickname = gameSettings.getPlayerList().get(0).getName();
+ connectionControl.nickname = gameSettings.getPlayerList().get(0)
+ .getName();
testRoundState = new RoundState(gameSettings, null);
testRound = new NetworkRoundControl(testRoundState, view,
@@ -67,8 +71,8 @@ public class NetworkRoundControlTest {
IPlayer player = testRoundState.getNthPlayer(i);
assertSame(gameSettings.getPlayerList().get(i),
player.getPlayerSettings());
- assertEquals(gameSettings.getNumberOfStonesDealt(), player.getHand()
- .getSize());
+ assertEquals(gameSettings.getNumberOfStonesDealt(), player
+ .getHand().getSize());
}
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);
connectionControl.turnStarted = false;
@@ -95,7 +100,8 @@ public class NetworkRoundControlTest {
connectionControl.nextPlayer = false;
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(1),
+ testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
@@ -107,50 +113,59 @@ public class NetworkRoundControlTest {
connectionControl.nextPlayer = false;
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(2),
+ testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded);
- connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo(
- testRoundState.getTable(), null, Collections.<StoneSet> emptyList()));
+ connectionControl.turnEndEvent.emit(testRoundState,
+ new InvalidTurnInfo(testRoundState.getTable(), null,
+ Collections.<StoneSet> emptyList()));
assertFalse(connectionControl.nextPlayer);
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(3),
+ testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded);
- connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo(
- testRoundState.getTable(), null, Collections.<StoneSet> emptyList()));
+ connectionControl.turnEndEvent.emit(testRoundState,
+ new InvalidTurnInfo(testRoundState.getTable(), null,
+ Collections.<StoneSet> emptyList()));
assertFalse(connectionControl.nextPlayer);
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(0),
+ testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded);
}
+ /** */
@Test
public void testClientRound() {
- connectionControl.nickname = gameSettings.getPlayerList().get(2).getName();
+ connectionControl.nickname = gameSettings.getPlayerList().get(2)
+ .getName();
testRoundState = new RoundState(gameSettings, null);
for (int i = 0; i < 4; ++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.turnEnded = false;
@@ -159,33 +174,38 @@ public class NetworkRoundControlTest {
connectionControl.roundStateUpdateEvent.emit(testRoundState);
- assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(0),
+ testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded);
- connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo(
- testRoundState.getTable(), null, Collections.<StoneSet> emptyList()));
+ connectionControl.turnEndEvent.emit(testRoundState,
+ new InvalidTurnInfo(testRoundState.getTable(), null,
+ Collections.<StoneSet> emptyList()));
assertFalse(connectionControl.turnEnded);
assertFalse(connectionControl.nextPlayer);
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(1), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(1),
+ testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded);
- connectionControl.turnEndEvent.emit(testRoundState, new InvalidTurnInfo(
- testRoundState.getTable(), null, Collections.<StoneSet> emptyList()));
+ connectionControl.turnEndEvent.emit(testRoundState,
+ new InvalidTurnInfo(testRoundState.getTable(), null,
+ Collections.<StoneSet> emptyList()));
assertFalse(connectionControl.nextPlayer);
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(2),
+ testRoundState.getActivePlayer());
assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit();
@@ -199,7 +219,8 @@ public class NetworkRoundControlTest {
connectionControl.nextPlayer = false;
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(3), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(3),
+ testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
@@ -211,7 +232,8 @@ public class NetworkRoundControlTest {
connectionControl.nextPlayer = false;
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(0),
+ testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;