summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mock/jrummikub/model/MockRoundState.java2
-rw-r--r--mock/jrummikub/util/MockEvent.java9
-rw-r--r--mock/jrummikub/util/MockEvent1.java2
-rw-r--r--mock/jrummikub/util/MockEvent2.java3
-rw-r--r--mock/jrummikub/util/MockEvent3.java15
-rw-r--r--mock/jrummikub/view/MockView.java13
-rw-r--r--src/jrummikub/control/GameControl.java8
-rw-r--r--src/jrummikub/control/RoundControl.java80
-rw-r--r--src/jrummikub/control/network/NetworkRoundControl.java65
-rw-r--r--src/jrummikub/control/turn/AbstractTurnControl.java4
-rw-r--r--src/jrummikub/model/GameState.java26
-rw-r--r--src/jrummikub/model/IRoundState.java2
-rw-r--r--src/jrummikub/model/RoundState.java8
-rw-r--r--src/jrummikub/view/IView.java8
-rw-r--r--src/jrummikub/view/impl/StartTurnPanel.java99
-rw-r--r--src/jrummikub/view/impl/View.java14
-rw-r--r--test/jrummikub/control/GameControlTest.java2
-rw-r--r--test/jrummikub/control/RoundControlTest.java105
-rw-r--r--test/jrummikub/control/network/GameJoinControlTest.java12
-rw-r--r--test/jrummikub/control/network/NetworkRoundControlTest.java103
20 files changed, 343 insertions, 237 deletions
diff --git a/mock/jrummikub/model/MockRoundState.java b/mock/jrummikub/model/MockRoundState.java
index 9b36906..b92883a 100644
--- a/mock/jrummikub/model/MockRoundState.java
+++ b/mock/jrummikub/model/MockRoundState.java
@@ -69,7 +69,7 @@ public class MockRoundState implements IRoundState {
}
@Override
- public StoneHeap getGameHeap() {
+ public StoneHeap getStoneHeap() {
return gameHeap;
}
diff --git a/mock/jrummikub/util/MockEvent.java b/mock/jrummikub/util/MockEvent.java
index 3d4c56a..169e1e7 100644
--- a/mock/jrummikub/util/MockEvent.java
+++ b/mock/jrummikub/util/MockEvent.java
@@ -1,6 +1,7 @@
package jrummikub.util;
import java.util.HashSet;
+
/**
* Mock class for Events
*/
@@ -11,8 +12,8 @@ public class MockEvent implements IEvent {
@Override
public Connection add(final IListener listener) {
listeners.add(listener);
- return new Connection() {
-
+ return new Connection() {
+
@Override
public void remove() {
MockEvent.this.remove(listener);
@@ -24,10 +25,10 @@ public class MockEvent implements IEvent {
public void remove(IListener listener) {
listeners.remove(listener);
}
-
+
/** */
public void emit() {
- for (IListener listener : listeners) {
+ for (IListener listener : new HashSet<IListener>(listeners)) {
listener.handle();
}
}
diff --git a/mock/jrummikub/util/MockEvent1.java b/mock/jrummikub/util/MockEvent1.java
index 955215c..d8e2824 100644
--- a/mock/jrummikub/util/MockEvent1.java
+++ b/mock/jrummikub/util/MockEvent1.java
@@ -34,7 +34,7 @@ public class MockEvent1<T> implements IEvent1<T> {
* the event parameter
*/
public void emit(T value) {
- for (IListener1<T> listener : listeners) {
+ for (IListener1<T> listener : new HashSet<IListener1<T>>(listeners)) {
listener.handle(value);
}
}
diff --git a/mock/jrummikub/util/MockEvent2.java b/mock/jrummikub/util/MockEvent2.java
index bb4582f..5c25ca4 100644
--- a/mock/jrummikub/util/MockEvent2.java
+++ b/mock/jrummikub/util/MockEvent2.java
@@ -38,7 +38,8 @@ public class MockEvent2<T1, T2> implements IEvent2<T1, T2> {
* the second event parameter
*/
public void emit(T1 value1, T2 value2) {
- for (IListener2<T1, T2> listener : listeners) {
+ for (IListener2<T1, T2> listener : new HashSet<IListener2<T1, T2>>(
+ listeners)) {
listener.handle(value1, value2);
}
}
diff --git a/mock/jrummikub/util/MockEvent3.java b/mock/jrummikub/util/MockEvent3.java
index 62c3ed9..c154ca0 100644
--- a/mock/jrummikub/util/MockEvent3.java
+++ b/mock/jrummikub/util/MockEvent3.java
@@ -6,11 +6,11 @@ import java.util.HashSet;
* Mock class for Event2s
*
* @param <T1>
- * first event type
+ * first event type
* @param <T2>
- * second event type
+ * second event type
* @param <T3>
- * third event type
+ * third event type
*/
public class MockEvent3<T1, T2, T3> implements IEvent3<T1, T2, T3> {
/** */
@@ -35,14 +35,15 @@ public class MockEvent3<T1, T2, T3> implements IEvent3<T1, T2, T3> {
/**
* @param value1
- * the first event parameter
+ * the first event parameter
* @param value2
- * the second event parameter
+ * the second event parameter
* @param value3
- * the third event parameter
+ * the third event parameter
*/
public void emit(T1 value1, T2 value2, T3 value3) {
- for (IListener3<T1, T2, T3> listener : listeners) {
+ for (IListener3<T1, T2, T3> listener : new HashSet<IListener3<T1, T2, T3>>(
+ listeners)) {
listener.handle(value1, value2, value3);
}
}
diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java
index 1cdd732..c5f87ed 100644
--- a/mock/jrummikub/view/MockView.java
+++ b/mock/jrummikub/view/MockView.java
@@ -318,6 +318,17 @@ public class MockView implements IView {
@Override
public void showServerStartupError(boolean alreadyRunning) {
// TODO Auto-generated method stub
-
+
+ }
+
+ public void setRedealedPlayerName(String name) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void setLastStonePlayerName(String name) {
+ // TODO Auto-generated method stub
+
}
}
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java
index 1f659f8..48c1b85 100644
--- a/src/jrummikub/control/GameControl.java
+++ b/src/jrummikub/control/GameControl.java
@@ -8,6 +8,7 @@ import jrummikub.model.GameSettings;
import jrummikub.model.GameState;
import jrummikub.model.IPlayer;
import jrummikub.model.IRoundState;
+import jrummikub.model.PlayerSettings;
import jrummikub.model.RoundState;
import jrummikub.model.Score;
import jrummikub.util.Connection;
@@ -183,14 +184,15 @@ public class GameControl {
roundControl.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override
public void handle(Score roundScore) {
+ gameState.setLastPlayerRedealed(null);
endOfRound(roundScore);
}
});
- roundControl.getRestartRoundEvent().add(new IListener() {
-
+ roundControl.getRestartRoundEvent().add(new IListener1<PlayerSettings>() {
@Override
- public void handle() {
+ public void handle(PlayerSettings player) {
+ gameState.setLastPlayerRedealed(player);
restartRound();
}
});
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 4227741..2bcbc7e 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -8,7 +8,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import jrummikub.control.turn.AIControl;
import jrummikub.control.turn.ITurnControl;
import jrummikub.control.turn.TurnControlFactory;
import jrummikub.control.turn.TurnMode;
@@ -16,15 +15,14 @@ import jrummikub.model.IHand;
import jrummikub.model.IPlayer;
import jrummikub.model.IRoundState;
import jrummikub.model.ITable;
+import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
import jrummikub.model.Position;
import jrummikub.model.Score;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
import jrummikub.util.Connection;
-import jrummikub.util.Event;
import jrummikub.util.Event1;
-import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IListener;
import jrummikub.util.IListener2;
@@ -113,7 +111,7 @@ public class RoundControl {
private ITurnControl turnControl;
protected IRoundState roundState;
private IView view;
- private Event restartRoundEvent = new Event();
+ private Event1<PlayerSettings> restartRoundEvent = new Event1<PlayerSettings>();
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
private Event1<Score> endOfRoundEvent = new Event1<Score>();
protected List<Connection> connections = new ArrayList<Connection>();
@@ -180,7 +178,6 @@ public class RoundControl {
* Continue a saved round after loading
*/
public void continueRound() {
-
connections.add(view.getStartTurnEvent().add(new IListener() {
@Override
public void handle() {
@@ -222,6 +219,35 @@ public class RoundControl {
roundStateUpdateEvent.emit(state);
}
+ protected BottomPanelType showStartTurnPanel() {
+ boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
+ .getType() == HUMAN;
+ boolean oneHuman = roundState.getGameSettings().oneHuman();
+
+ if (!isHuman) {
+ return null;
+ }
+
+ if (roundState.getLastPlayer() != null) {
+ view.setLastStonePlayerName(roundState.getLastPlayer()
+ .getPlayerSettings().getName());
+ return BottomPanelType.START_LAST_TURN_PANEL;
+ }
+
+ if (roundState.getTurnNumber() < 1
+ && roundState.getGameState().getLastPlayerRedealed() != null) {
+ view.setRedealedPlayerName(roundState.getGameState()
+ .getLastPlayerRedealed().getName());
+ return BottomPanelType.START_REDEAL_TURN_PANEL;
+ }
+
+ if (oneHuman) {
+ return null;
+ }
+
+ return BottomPanelType.START_TURN_PANEL;
+ }
+
/**
* Prepare a player's turn by checking the player types and setting the
* correct turn control
@@ -229,12 +255,7 @@ public class RoundControl {
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)) {
+ if (showStartTurnPanel() == null) {
startTurn();
}
}
@@ -245,12 +266,9 @@ public class RoundControl {
protected void doPrepareTurn() {
updateSidePanel();
- boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
- .getType() == HUMAN;
- boolean oneHuman = roundState.getGameSettings().oneHuman();
-
- if (isHuman && !oneHuman) {
- view.setBottomPanel(BottomPanelType.START_TURN_PANEL);
+ BottomPanelType startTurnPanel = showStartTurnPanel();
+ if (startTurnPanel != null) {
+ view.setBottomPanel(startTurnPanel);
}
view.getTablePanel().setStoneSets(roundState.getTable().clone());
@@ -259,19 +277,13 @@ public class RoundControl {
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()
.getColor());
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut());
-
- turnControl = createTurnControl(roundState.getActivePlayer()
- .getPlayerSettings().getType());
}
/**
* Start a players turn with the correct turn control
*/
protected void startTurn() {
- if (turnControl == null) {
- doPrepareTurn();
- }
-
+ doPrepareTurn();
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
.getType() == HUMAN;
@@ -294,6 +306,7 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(turnMode);
}
+ turnControl = createTurnControl();
turnControl.setup(
new ITurnControl.TurnInfo(roundState, turnMode, mayPause),
roundState.getGameSettings(), view);
@@ -330,7 +343,7 @@ public class RoundControl {
view.getSidePanel().setPlayers(players);
view.getSidePanel().setHeapCapacity(
roundState.getGameSettings().getTotalStones());
- view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize());
+ view.getSidePanel().setHeapSize(roundState.getStoneHeap().getSize());
}
/**
@@ -349,8 +362,9 @@ public class RoundControl {
* of the new turn control
* @return the new turn control
*/
- protected ITurnControl createTurnControl(Type type) {
- return TurnControlFactory.getFactory(type).create();
+ protected ITurnControl createTurnControl() {
+ return TurnControlFactory.getFactory(
+ roundState.getActivePlayer().getPlayerSettings().getType()).create();
}
/**
@@ -361,11 +375,11 @@ public class RoundControl {
for (int i = 0; i < roundState.getPlayerCount(); i++) {
IHand hand = roundState.getNthNextPlayer(i).getHand();
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
- hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0));
+ hand.drop(roundState.getStoneHeap().drawStone(), new Position(0, 0));
}
}
- view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize());
+ view.getSidePanel().setHeapSize(roundState.getStoneHeap().getSize());
}
/**
@@ -429,7 +443,7 @@ public class RoundControl {
}
if (roundState.getLastPlayer() == null) {
- if (roundState.getGameHeap().getSize() == 0) {
+ if (roundState.getStoneHeap().getSize() == 0) {
roundState.setLastPlayer(roundState.getActivePlayer());
roundState.nextPlayer();
roundState.nextTurn();
@@ -547,7 +561,7 @@ public class RoundControl {
*
* @return the event
*/
- public IEvent getRestartRoundEvent() {
+ public IEvent1<PlayerSettings> getRestartRoundEvent() {
return restartRoundEvent;
}
@@ -556,10 +570,12 @@ public class RoundControl {
* to do so
*/
protected void redeal() {
+ view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
+
turnControl = null;
for (Connection c : new ArrayList<Connection>(connections)) {
c.remove();
}
- restartRoundEvent.emit();
+ restartRoundEvent.emit(roundState.getActivePlayer().getPlayerSettings());
}
}
diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java
index af7f675..05a3424 100644
--- a/src/jrummikub/control/network/NetworkRoundControl.java
+++ b/src/jrummikub/control/network/NetworkRoundControl.java
@@ -4,7 +4,6 @@ import jrummikub.control.RoundControl;
import jrummikub.control.turn.ITurnControl;
import jrummikub.model.IRoundState;
import jrummikub.model.ITable;
-import jrummikub.model.PlayerSettings.Type;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.view.IView;
@@ -14,6 +13,7 @@ import jrummikub.view.IView;
*/
public class NetworkRoundControl extends RoundControl {
private IConnectionControl connectionControl;
+ private boolean wasActive;
private boolean currentlyActive;
/**
@@ -33,6 +33,7 @@ public class NetworkRoundControl extends RoundControl {
super(roundState, view, false);
this.connectionControl = connectionControl;
+ wasActive = startActive;
currentlyActive = startActive;
connections.add(connectionControl.getRoundStateUpdateEvent().add(
@@ -40,22 +41,21 @@ public class NetworkRoundControl extends RoundControl {
@Override
public void handle(IRoundState state) {
setRoundState(state);
+ prepareTurn();
}
}));
- 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() {
+ NetworkRoundControl.super.startTurn();
+ }
+ }));
+ connections.add(connectionControl.getNextPlayerEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ NetworkRoundControl.super.nextPlayer();
+ }
+ }));
}
@Override
@@ -69,30 +69,39 @@ public class NetworkRoundControl extends RoundControl {
}
@Override
- protected ITurnControl createTurnControl(Type type) {
- switch (type) {
- case HUMAN:
- currentlyActive = true;
- break;
- case NETWORK:
- currentlyActive = false;
- break;
- }
-
+ protected ITurnControl createTurnControl() {
if (!currentlyActive) {
return new NetworkTurnControl(connectionControl);
}
- return super.createTurnControl(type);
+ return super.createTurnControl();
}
@Override
protected void prepareTurn() {
- if (currentlyActive) {
- connectionControl.startTurn();
+ switch (roundState.getActivePlayer().getPlayerSettings().getType()) {
+ case HUMAN:
+ currentlyActive = true;
+ break;
+ case NETWORK:
+ currentlyActive = false;
+ break;
}
doPrepareTurn();
+
+ if (showStartTurnPanel() == null) {
+ if (currentlyActive) {
+ connectionControl.startTurn();
+ }
+ }
+ }
+
+ @Override
+ protected void startTurn() {
+ if (currentlyActive) {
+ connectionControl.startTurn();
+ }
}
@Override
diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java
index 9bdd6e2..19a2be4 100644
--- a/src/jrummikub/control/turn/AbstractTurnControl.java
+++ b/src/jrummikub/control/turn/AbstractTurnControl.java
@@ -226,7 +226,7 @@ public abstract class AbstractTurnControl implements ITurnControl {
Set<Stone> tableDiff = tableDifference(turnInfo.getOldTable(),
turnInfo.getTable());
// deal penalty, reset
- turnInfo.getRoundState().getGameHeap().putBack(tableDiff);
+ turnInfo.getRoundState().getStoneHeap().putBack(tableDiff);
turnInfo.getRoundState().getActivePlayer().setLastTurnInvalid(true);
dealPenalty(tableDiff.size());
}
@@ -240,7 +240,7 @@ public abstract class AbstractTurnControl implements ITurnControl {
rowCount++;
}
- hand.drop(turnInfo.getRoundState().getGameHeap().drawStone(),
+ hand.drop(turnInfo.getRoundState().getStoneHeap().drawStone(),
new Position(Hand.WIDTH - 1, rowCount - 1));
}
diff --git a/src/jrummikub/model/GameState.java b/src/jrummikub/model/GameState.java
index ee5c2d3..7cd38ab 100644
--- a/src/jrummikub/model/GameState.java
+++ b/src/jrummikub/model/GameState.java
@@ -13,6 +13,7 @@ public class GameState implements Serializable {
private int firstRoundFirstPlayer;
private ArrayList<Score> scores = new ArrayList<Score>();
+ private PlayerSettings lastPlayerRedealed;
/**
* Gets the number of the first player of the first round
@@ -34,6 +35,25 @@ public class GameState implements Serializable {
}
/**
+ * Sets the player that has redealed last
+ *
+ * @param lastPlayerRedealed
+ * the player to set
+ */
+ public void setLastPlayerRedealed(PlayerSettings lastPlayerRedealed) {
+ this.lastPlayerRedealed = lastPlayerRedealed;
+ }
+
+ /**
+ * Returns the player that has redealed last
+ *
+ * @return the player
+ */
+ public PlayerSettings getLastPlayerRedealed() {
+ return lastPlayerRedealed;
+ }
+
+ /**
* Returns the list of players' scores in the rounds played before
*
* @return the list of scores
@@ -45,8 +65,10 @@ public class GameState implements Serializable {
/**
* Returns whether players have won
*
- * @param points the player's points
- * @param wins the number of wins per player
+ * @param points
+ * the player's points
+ * @param wins
+ * the number of wins per player
* @return whether a player has won
*/
private Boolean[] getWinners(Integer[] points, int[] wins) {
diff --git a/src/jrummikub/model/IRoundState.java b/src/jrummikub/model/IRoundState.java
index 6d43f02..3eedc4c 100644
--- a/src/jrummikub/model/IRoundState.java
+++ b/src/jrummikub/model/IRoundState.java
@@ -51,7 +51,7 @@ public interface IRoundState extends Serializable {
*
* @return heap of stones
*/
- public StoneHeap getGameHeap();
+ public StoneHeap getStoneHeap();
/**
* Returns the player that would be the active player after i turns
diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java
index 04a977d..f7a75d5 100644
--- a/src/jrummikub/model/RoundState.java
+++ b/src/jrummikub/model/RoundState.java
@@ -12,7 +12,7 @@ public class RoundState implements IRoundState {
private ITable table;
private ArrayList<Player> players;
private int activePlayer;
- private StoneHeap gameHeap;
+ private StoneHeap stoneHeap;
private IPlayer lastPlayer;
private int turnNumber;
@@ -38,7 +38,7 @@ public class RoundState implements IRoundState {
turnNumber = 1 - gameSettings.getPlayerList().size();
activePlayer = 0;
- gameHeap = new StoneHeap(gameSettings);
+ stoneHeap = new StoneHeap(gameSettings);
}
@Override
@@ -94,8 +94,8 @@ public class RoundState implements IRoundState {
}
@Override
- public StoneHeap getGameHeap() {
- return gameHeap;
+ public StoneHeap getStoneHeap() {
+ return stoneHeap;
}
@Override
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index 91a2e23..c3670cb 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -61,6 +61,10 @@ public interface IView {
*/
public void setCurrentPlayerName(String playerName);
+ public void setRedealedPlayerName(String name);
+
+ public void setLastStonePlayerName(String name);
+
/**
* Sets the stones that are to be painted selected
*
@@ -368,6 +372,10 @@ public interface IView {
/** */
START_TURN_PANEL,
/** */
+ START_REDEAL_TURN_PANEL,
+ /** */
+ START_LAST_TURN_PANEL,
+ /** */
INVALID_TURN_PANEL,
/** */
HUMAN_HAND_PANEL,
diff --git a/src/jrummikub/view/impl/StartTurnPanel.java b/src/jrummikub/view/impl/StartTurnPanel.java
index 4c895b5..d3f139d 100644
--- a/src/jrummikub/view/impl/StartTurnPanel.java
+++ b/src/jrummikub/view/impl/StartTurnPanel.java
@@ -23,17 +23,23 @@ import jrummikub.view.IView.BottomPanelType;
class StartTurnPanel extends JPanel {
private final static int PANEL_INSET = 15;
private final static int PANEL_SEPARATOR = 10;
- private final static float PANEL_FIRST_LINE_HEIGHT = 0.375f;
+ private final static float PANEL_FIRST_LINE_HEIGHT = 0.2f;
private final static int PANEL_MAX_WIDTH = 180;
private final static float MAX_BUTTON_FONT_SIZE = 12;
private JLabel startTurnLabel;
+ private JLabel extraLabel;
private JButton startTurnButton;
private Event startTurnEvent = new Event();
private Event acknowledgeInvalidEvent = new Event();
private Event buttonEvent = startTurnEvent;
+ private BottomPanelType type;
+ private Color currentPlayerColor;
+ private String currentPlayerName;
+ private String redealedPlayerName;
+ private String lastStonePlayerName;
/**
* Creates a new StartTurnPanel
@@ -49,6 +55,12 @@ class StartTurnPanel extends JPanel {
startTurnLabel.putClientProperty("html.disable", Boolean.TRUE);
add(startTurnLabel);
+ extraLabel = new JLabel();
+ extraLabel.setHorizontalAlignment(JLabel.CENTER);
+ extraLabel.setVerticalAlignment(JLabel.CENTER);
+ extraLabel.putClientProperty("html.disable", Boolean.TRUE);
+ add(extraLabel);
+
startTurnButton = new JButton("Zug beginnen");
startTurnButton.addActionListener(new ActionListener() {
@Override
@@ -66,14 +78,6 @@ class StartTurnPanel extends JPanel {
});
}
- void setCurrentPlayerName(String playerName) {
- startTurnLabel.setText(playerName + " ist jetzt an der Reihe.");
- }
-
- void setCurrentPlayerColor(Color color) {
- startTurnLabel.setIcon(ImageUtil.createColorIcon(color, 12, 1));
- }
-
void setInitialMeldError(int points) {
startTurnLabel.setIcon(null);
startTurnLabel.setText("Es wurden weniger als " + points
@@ -105,34 +109,83 @@ class StartTurnPanel extends JPanel {
int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT);
int buttonWidth = width;
- int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight;
+ int buttonHeight = height - 2 * PANEL_SEPARATOR - 2 * firstLineHeight;
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
if (fontSize > MAX_BUTTON_FONT_SIZE)
fontSize = MAX_BUTTON_FONT_SIZE;
- startTurnLabel.setBounds(x, y, width, firstLineHeight);
- startTurnButton.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR,
+ if (type == BottomPanelType.START_REDEAL_TURN_PANEL
+ || type == BottomPanelType.START_LAST_TURN_PANEL) {
+ startTurnLabel.setBounds(x, y, width, firstLineHeight);
+ extraLabel.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR, width,
+ firstLineHeight);
+ extraLabel.setVisible(true);
+ } else {
+ startTurnLabel.setBounds(x, y, width, 2 * firstLineHeight
+ + PANEL_SEPARATOR);
+ extraLabel.setVisible(false);
+ }
+ startTurnButton.setBounds(x, y + 2 * firstLineHeight + 2 * PANEL_SEPARATOR,
buttonWidth, buttonHeight);
startTurnButton.setFont(startTurnButton.getFont().deriveFont(fontSize));
}
- public void setType(BottomPanelType type) {
+ void setCurrentPlayerName(String playerName) {
+ currentPlayerName = playerName;
+ update();
+ }
+
+ void setCurrentPlayerColor(Color color) {
+ currentPlayerColor = color;
+ update();
+ }
+
+ void setRedealedPlayerName(String name) {
+ redealedPlayerName = name;
+ update();
+ }
+
+ void setLastStonePlayerName(String name) {
+ lastStonePlayerName = name;
+ update();
+ }
+
+ void setType(BottomPanelType type) {
+ this.type = type;
+ update();
+ }
+
+ private void update() {
if (type == null) {
return;
}
+ startTurnLabel
+ .setIcon(ImageUtil.createColorIcon(currentPlayerColor, 12, 1));
+ startTurnLabel.setText(currentPlayerName + " ist jetzt an der Reihe.");
+ extraLabel.setText("");
+ startTurnButton.setText("Zug beginnen");
+ buttonEvent = startTurnEvent;
+
switch (type) {
- case START_TURN_PANEL:
- startTurnButton.setText("Zug beginnen");
- buttonEvent = startTurnEvent;
- break;
- case INVALID_TURN_PANEL:
- startTurnLabel.setIcon(null);
- startTurnLabel.setText("Es liegen ung\u00FCltige Serien auf dem Tisch.");
- startTurnButton.setText("N\u00E4chster Spieler");
- buttonEvent = acknowledgeInvalidEvent;
- break;
+ case START_REDEAL_TURN_PANEL:
+ extraLabel.setText(redealedPlayerName + " hat neu geben lassen.");
+ break;
+
+ case START_LAST_TURN_PANEL:
+ extraLabel.setText(lastStonePlayerName
+ + " hat den letzten Stein gezogen.");
+ break;
+
+ case INVALID_TURN_PANEL:
+ startTurnLabel.setIcon(null);
+ startTurnLabel
+ .setText("Es liegen ung\u00FCltige Serien auf dem Tisch.");
+ startTurnButton.setText("N\u00E4chster Spieler");
+ buttonEvent = acknowledgeInvalidEvent;
+ break;
}
+ rescale();
}
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index fe2c1eb..4940999 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -582,6 +582,16 @@ public class View extends JFrame implements IView {
}
@Override
+ public void setRedealedPlayerName(String name) {
+ startTurnPanel.setRedealedPlayerName(name);
+ }
+
+ @Override
+ public void setLastStonePlayerName(String name) {
+ startTurnPanel.setLastStonePlayerName(name);
+ }
+
+ @Override
public void setCurrentPlayerHasLaidOut(boolean hasLaidOut) {
playerPanel.setHasLaidOut(hasLaidOut);
}
@@ -657,7 +667,9 @@ public class View extends JFrame implements IView {
}
private void doSetBottomPanel(BottomPanelType type) {
- boolean showStartTurnPanel = (type == BottomPanelType.START_TURN_PANEL || type == BottomPanelType.INVALID_TURN_PANEL);
+ boolean showStartTurnPanel = (type == BottomPanelType.START_TURN_PANEL
+ || type == BottomPanelType.START_REDEAL_TURN_PANEL
+ || type == BottomPanelType.START_LAST_TURN_PANEL || type == BottomPanelType.INVALID_TURN_PANEL);
startTurnPanel.setType(type);
startTurnPanel.setVisible(showStartTurnPanel);
diff --git a/test/jrummikub/control/GameControlTest.java b/test/jrummikub/control/GameControlTest.java
index 7555714..a9273ef 100644
--- a/test/jrummikub/control/GameControlTest.java
+++ b/test/jrummikub/control/GameControlTest.java
@@ -92,7 +92,7 @@ public class GameControlTest {
view.playerPanel.endTurnEvent.emit();
view.startTurnEvent.emit();
view.playerPanel.redealEvent.emit();
- assertSame(BottomPanelType.START_TURN_PANEL, view.bottomPanelType);
+ assertSame(BottomPanelType.START_REDEAL_TURN_PANEL, view.bottomPanelType);
view.startTurnEvent.emit();
assertSame(firstPlayer, gameControl.roundControl.roundState
.getActivePlayer().getPlayerSettings());
diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java
index 6b4cb23..a6e1bbb 100644
--- a/test/jrummikub/control/RoundControlTest.java
+++ b/test/jrummikub/control/RoundControlTest.java
@@ -10,6 +10,7 @@ import java.util.List;
import jrummikub.control.turn.TurnMode;
import jrummikub.model.GameSettings;
+import jrummikub.model.GameState;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
import jrummikub.model.IPlayer;
@@ -22,7 +23,6 @@ import jrummikub.model.RoundState;
import jrummikub.model.Score;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
-import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.Pair;
import jrummikub.view.IView.BottomPanelType;
@@ -86,8 +86,9 @@ public class RoundControlTest {
public void setup() {
view = new MockView();
testRoundState = new MockRoundState();
+ testRoundState.gameState = new GameState();
testRound = new RoundControl(testRoundState, view);
- Stone stone = testRoundState.getGameHeap().drawStone();
+ Stone stone = testRoundState.getStoneHeap().drawStone();
testRoundState.table.drop(new StoneSet(stone), new Position(5, 0));
testTable = new MockTable();
testTable.sets.add(testRoundState.table.sets.get(0));
@@ -99,24 +100,21 @@ public class RoundControlTest {
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));
- roundState = new RoundState(gameSettings, null);
+ gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
+ gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
+ roundState = new RoundState(gameSettings, new GameState());
roundControl = new RoundControl(roundState, view);
}
private void checkCorrectlyDealt() {
GameSettings settings = testRoundState.getGameSettings();
- int totalStones = settings.getHighestValue()
- * settings.getStoneSetNumber()
+ int totalStones = settings.getHighestValue() * settings.getStoneSetNumber()
* settings.getStoneColors().size() + settings.getJokerNumber();
assertEquals(
totalStones - testRoundState.getPlayerCount()
* settings.getNumberOfStonesDealt()
- - testRoundState.table.getSize(), testRoundState
- .getGameHeap().getSize());
+ - testRoundState.table.getSize(), testRoundState.getStoneHeap()
+ .getSize());
for (int i = 0; i < testRoundState.getPlayerCount(); i++) {
assertEquals(settings.getNumberOfStonesDealt(), testRoundState
.getNthNextPlayer(i).getHand().getSize());
@@ -187,8 +185,8 @@ public class RoundControlTest {
view.tablePanel.clickEvent.emit(new Position(0, 0));
view.playerPanel.endTurnEvent.emit();
- assertFalse(roundState
- .getNthNextPlayer(roundState.getPlayerCount() - 1).getLaidOut());
+ assertFalse(roundState.getNthNextPlayer(roundState.getPlayerCount() - 1)
+ .getLaidOut());
assertEquals(0, roundState.getTable().getSize());
assertEquals(14 + 6, roundState.getActivePlayer().getHand().getSize());
}
@@ -210,8 +208,7 @@ public class RoundControlTest {
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(0, roundState.getTable().getSize());
- assertEquals(14 + 1, roundState.getNthNextPlayer(-1).getHand()
- .getSize());
+ assertEquals(14 + 1, roundState.getNthNextPlayer(-1).getHand().getSize());
}
/** Threshold=30 */
@@ -248,8 +245,7 @@ public class RoundControlTest {
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(0, roundState.getTable().getSize());
- assertEquals(14 + 9, roundState.getNthNextPlayer(-1).getHand()
- .getSize());
+ assertEquals(14 + 9, roundState.getNthNextPlayer(-1).getHand().getSize());
}
private void dropStonesOnHand(IHand hand, List<Stone> stones) {
@@ -308,8 +304,7 @@ public class RoundControlTest {
view.acknowledgeInvalidEvent.emit();
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(2, roundState.getTable().getSize());
- assertEquals(14 + 6, roundState.getNthNextPlayer(-1).getHand()
- .getSize());
+ assertEquals(14 + 6, roundState.getNthNextPlayer(-1).getHand().getSize());
}
/** Threshold=30 */
@@ -361,8 +356,7 @@ public class RoundControlTest {
view.acknowledgeInvalidEvent.emit();
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(2, roundState.getTable().getSize());
- assertEquals(14 + 7, roundState.getNthNextPlayer(-1).getHand()
- .getSize());
+ assertEquals(14 + 7, roundState.getNthNextPlayer(-1).getHand().getSize());
}
/** */
@@ -415,8 +409,7 @@ public class RoundControlTest {
view.acknowledgeInvalidEvent.emit();
assertFalse(roundState.getNthNextPlayer(-1).getLaidOut());
assertEquals(2, roundState.getTable().getSize());
- assertEquals(14 + 3, roundState.getNthNextPlayer(-1).getHand()
- .getSize());
+ assertEquals(14 + 3, roundState.getNthNextPlayer(-1).getHand().getSize());
}
/** Threshold=30 */
@@ -499,8 +492,9 @@ public class RoundControlTest {
testTable.valid = true;
testTable.sets.clear();
testTable.drop(
- new StoneSet(Arrays.asList(blueEight, blackEight, redEight,
- orangeEight)), new Position(0, 0));
+ new StoneSet(Arrays
+ .asList(blueEight, blackEight, redEight, orangeEight)),
+ new Position(0, 0));
oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
@@ -529,9 +523,10 @@ public class RoundControlTest {
testTable.valid = false;
testTable.sets.clear();
- testTable.drop(
- new StoneSet(Arrays.asList(blueEight, blackEight, redEight,
- blackFour)), new Position(0, 0));
+ testTable
+ .drop(
+ new StoneSet(Arrays.asList(blueEight, blackEight, redEight,
+ blackFour)), new Position(0, 0));
oldTable.clonedTable = testTable;
view.startTurnEvent.emit();
@@ -587,8 +582,9 @@ public class RoundControlTest {
MockTable oldTable = testRoundState.table;
oldTable.sets.clear();
oldTable.drop(
- new StoneSet(Arrays.asList(blueEight, blackEight, redEight,
- orangeEight)), new Position(0, 0));
+ new StoneSet(Arrays
+ .asList(blueEight, blackEight, redEight, orangeEight)),
+ new Position(0, 0));
testTable.valid = false;
testTable.sets.clear();
@@ -672,7 +668,7 @@ public class RoundControlTest {
}
});
- roundState.getGameHeap().drawStones(106 - 14 * 4 - 1);
+ roundState.getStoneHeap().drawStones(106 - 14 * 4 - 1);
roundControl.startRound();
for (int i = 0; i < 4; i++) {
@@ -713,20 +709,19 @@ public class RoundControlTest {
}
testRoundState.players.get(0).laidOut = true;
- testRoundState.players.get(0).hand.drop(new Stone(1, RED),
- new Position(0, 0));
- testRoundState.players.get(0).hand.drop(new Stone(2, RED),
- new Position(0, 0));
- testRoundState.players.get(1).laidOut = true;
- testRoundState.players.get(1).hand.drop(new Stone(RED), new Position(0,
+ testRoundState.players.get(0).hand.drop(new Stone(1, RED), new Position(0,
+ 0));
+ testRoundState.players.get(0).hand.drop(new Stone(2, RED), new Position(0,
0));
+ testRoundState.players.get(1).laidOut = true;
+ testRoundState.players.get(1).hand.drop(new Stone(RED), new Position(0, 0));
testRoundState.players.get(2).laidOut = false;
- testRoundState.players.get(2).hand.drop(new Stone(9, RED),
- new Position(0, 0));
- testRoundState.players.get(2).hand.drop(new Stone(10, RED),
- new Position(0, 0));
- testRoundState.players.get(2).hand.drop(new Stone(11, RED),
- new Position(0, 0));
+ testRoundState.players.get(2).hand.drop(new Stone(9, RED), new Position(0,
+ 0));
+ testRoundState.players.get(2).hand.drop(new Stone(10, RED), new Position(0,
+ 0));
+ testRoundState.players.get(2).hand.drop(new Stone(11, RED), new Position(0,
+ 0));
testRoundState.players.get(3).laidOut = true;
testRound.endOfRound();
@@ -760,19 +755,19 @@ public class RoundControlTest {
}
testRoundState.players.get(0).laidOut = true;
- testRoundState.players.get(0).hand.drop(new Stone(1, RED),
- new Position(0, 0));
- testRoundState.players.get(0).hand.drop(new Stone(2, RED),
- new Position(0, 0));
+ testRoundState.players.get(0).hand.drop(new Stone(1, RED), new Position(0,
+ 0));
+ testRoundState.players.get(0).hand.drop(new Stone(2, RED), new Position(0,
+ 0));
testRoundState.players.get(1).laidOut = true;
- testRoundState.players.get(1).hand.drop(new Stone(3, RED),
- new Position(0, 0));
+ testRoundState.players.get(1).hand.drop(new Stone(3, RED), new Position(0,
+ 0));
testRoundState.players.get(2).laidOut = true;
- testRoundState.players.get(2).hand.drop(new Stone(3, BLUE),
- new Position(0, 0));
+ testRoundState.players.get(2).hand.drop(new Stone(3, BLUE), new Position(0,
+ 0));
testRoundState.players.get(3).laidOut = false;
- testRoundState.players.get(3).hand.drop(new Stone(13, RED),
- new Position(0, 0));
+ testRoundState.players.get(3).hand.drop(new Stone(13, RED), new Position(0,
+ 0));
testRound.endOfRound();
assertTrue(roundEnded);
@@ -810,9 +805,9 @@ public class RoundControlTest {
/** */
@Test
public void testRedeal() {
- testRound.getRestartRoundEvent().add(new IListener() {
+ testRound.getRestartRoundEvent().add(new IListener1<PlayerSettings>() {
@Override
- public void handle() {
+ public void handle(PlayerSettings player) {
roundRestarted = true;
}
});
diff --git a/test/jrummikub/control/network/GameJoinControlTest.java b/test/jrummikub/control/network/GameJoinControlTest.java
index 179c583..e6168a5 100644
--- a/test/jrummikub/control/network/GameJoinControlTest.java
+++ b/test/jrummikub/control/network/GameJoinControlTest.java
@@ -33,13 +33,12 @@ public class GameJoinControlTest {
@Before
public void setup() {
mockConnection = new MockConnectionControl();
- mockConnection.nickname = "Karl";
view = new MockView();
loginData = new LoginData("Karl", "server", "password", "channel");
networkControl = new NetworkControl(loginData, mockConnection, null, view);
networkControl.startNetwork();
- mockConnection.connectedEvent.emit();
+ mockConnection.connectedEvent.emit();
}
/** */
@@ -52,7 +51,8 @@ public class GameJoinControlTest {
assertEquals(SettingsMode.NETWORK_JOIN, view.settingsPanel.settingsMode);
offerJoinedGame(id1, "Anne", "Karl");
view.settingsPanel.changePlayerColorEvent.emit(1, Color.GRAY);
- assertEquals(Type.HUMAN, mockConnection.getCurrentGame().getGameSettings().getPlayerList().get(1).getType());
+ assertEquals(Type.HUMAN, mockConnection.getCurrentGame().getGameSettings()
+ .getPlayerList().get(1).getType());
assertEquals(Color.GRAY, mockConnection.playerColor);
view.settingsPanel.backEvent.emit();
@@ -71,14 +71,14 @@ public class GameJoinControlTest {
mockConnection.gameOfferEvent.emit(gameData);
return gameData;
}
-
+
private GameData offerJoinedGame(UUID id, String host, String player) {
GameSettings gsettings = new GameSettings();
PlayerSettings psettings = new PlayerSettings(host, Color.BLACK);
- psettings.setType(Type.HUMAN);
+ psettings.setType(Type.NETWORK);
gsettings.getPlayerList().add(psettings);
PlayerSettings psettings2 = new PlayerSettings(player, Color.RED);
- psettings2.setType(Type.NETWORK);
+ psettings2.setType(Type.HUMAN);
gsettings.getPlayerList().add(psettings2);
GameData gameData = new GameData(id, gsettings, host);
mockConnection.gameOfferEvent.emit(gameData);
diff --git a/test/jrummikub/control/network/NetworkRoundControlTest.java b/test/jrummikub/control/network/NetworkRoundControlTest.java
index acf1e84..29ba122 100644
--- a/test/jrummikub/control/network/NetworkRoundControlTest.java
+++ b/test/jrummikub/control/network/NetworkRoundControlTest.java
@@ -8,6 +8,7 @@ import java.util.Collections;
import jrummikub.control.RoundControl.InvalidTurnInfo;
import jrummikub.control.turn.AIControl;
import jrummikub.model.GameSettings;
+import jrummikub.model.GameState;
import jrummikub.model.IPlayer;
import jrummikub.model.PlayerSettings;
import jrummikub.model.PlayerSettings.Type;
@@ -21,9 +22,6 @@ import jrummikub.view.MockView;
import org.junit.Before;
import org.junit.Test;
-/**
- * Tests for network round control
- */
public class NetworkRoundControlTest {
private MockConnectionControl connectionControl;
private MockView view;
@@ -32,7 +30,6 @@ public class NetworkRoundControlTest {
private GameSettings gameSettings;
- /** */
@Before
public void setup() {
AIControl.useBackgroundThread = false;
@@ -42,26 +39,20 @@ 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().get(1).setType(Type.COMPUTER);
- gameSettings.getPlayerList().get(2).setType(Type.NETWORK);
- gameSettings.getPlayerList().get(3).setType(Type.COMPUTER);
+ gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
+ gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
view = new MockView();
connectionControl = new MockConnectionControl();
}
- /** */
@Test
public void testHostRound() {
- connectionControl.nickname = gameSettings.getPlayerList().get(0)
- .getName();
+ 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, null);
+ testRoundState = new RoundState(gameSettings, new GameState());
testRound = new NetworkRoundControl(testRoundState, view,
connectionControl, true);
@@ -75,8 +66,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) {
@@ -88,8 +79,7 @@ public class NetworkRoundControlTest {
}
}
- assertSame(testRoundState.getNthPlayer(0),
- testRoundState.getActivePlayer());
+ assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
assertTrue(connectionControl.turnStarted);
connectionControl.turnStarted = false;
@@ -104,8 +94,7 @@ 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;
@@ -117,59 +106,52 @@ public class NetworkRoundControlTest {
connectionControl.nextPlayer = false;
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(2),
- testRoundState.getActivePlayer());
- assertTrue(connectionControl.turnStarted);
- connectionControl.turnStarted = false;
+ assertSame(testRoundState.getNthPlayer(2), 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(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());
- assertFalse(connectionControl.turnStarted);
+ assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
+ assertTrue(connectionControl.turnStarted);
+ connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded);
}
- /** */
@Test
public void testClientRound() {
- connectionControl.nickname = gameSettings.getPlayerList().get(2)
- .getName();
+ 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, null);
+ testRoundState = new RoundState(gameSettings, new GameState());
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;
@@ -178,39 +160,35 @@ 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());
- assertFalse(connectionControl.turnStarted);
+ assertSame(testRoundState.getNthPlayer(2), testRoundState.getActivePlayer());
+ assertTrue(connectionControl.turnStarted);
+ connectionControl.turnStarted = false;
connectionControl.turnStartEvent.emit();
@@ -223,8 +201,7 @@ 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;
@@ -236,10 +213,8 @@ public class NetworkRoundControlTest {
connectionControl.nextPlayer = false;
connectionControl.nextPlayerEvent.emit();
- assertSame(testRoundState.getNthPlayer(0),
- testRoundState.getActivePlayer());
- assertTrue(connectionControl.turnStarted);
- connectionControl.turnStarted = false;
+ assertSame(testRoundState.getNthPlayer(0), testRoundState.getActivePlayer());
+ assertFalse(connectionControl.turnStarted);
connectionControl.turnStartEvent.emit();
assertFalse(connectionControl.turnEnded);