summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/RoundControl.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-21 20:44:28 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-21 20:44:28 +0200
commit6acf9d6078d89eef5d2f2b19372b99baefd122af (patch)
treed9e74484006c39d17213bcee9b2ba907815832fd /src/jrummikub/control/RoundControl.java
parent5d0d5932971c456b85b142f9e483f0226dfefc2b (diff)
downloadJRummikub-6acf9d6078d89eef5d2f2b19372b99baefd122af.tar
JRummikub-6acf9d6078d89eef5d2f2b19372b99baefd122af.zip
Fix redealing in network mode
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@554 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/RoundControl.java')
-rw-r--r--src/jrummikub/control/RoundControl.java98
1 files changed, 46 insertions, 52 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 7f3135a..4227741 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -44,20 +44,19 @@ public class RoundControl {
/** There are invalid set(s) on the table */
INVALID_SETS,
/**
- * The player tried to modify the table without providing the initial
- * meld threshold first
+ * The player tried to modify the table without providing the initial meld
+ * threshold first
*/
INITIAL_MELD_ERROR,
/**
- * The player didn't provide enough points for the initial meld
- * threshold
+ * The player didn't provide enough points for the initial meld threshold
*/
NOT_ENOUGH_POINTS
}
/**
- * Table, stone sets and type of an invalid turn to allow a user to track
- * his own errors
+ * Table, stone sets and type of an invalid turn to allow a user to track his
+ * own errors
*/
public static class InvalidTurnInfo implements Serializable {
private static final long serialVersionUID = -3591000741414366776L;
@@ -70,11 +69,11 @@ public class RoundControl {
* Creates new InvalidTurnInfo
*
* @param table
- * the table after the turn
+ * the table after the turn
* @param type
- * the type of the invalid turn
+ * the type of the invalid turn
* @param invalidSets
- * the sets causing the turn to be invalid
+ * the sets causing the turn to be invalid
*/
public InvalidTurnInfo(ITable table, InvalidTurnType type,
Collection<StoneSet> invalidSets) {
@@ -124,9 +123,9 @@ public class RoundControl {
* Create a new RoundControl using the given roundState and view
*
* @param roundState
- * initial round state
+ * initial round state
* @param view
- * view used for user interaction
+ * view used for user interaction
*/
public RoundControl(IRoundState roundState, IView view) {
this(roundState, view, true);
@@ -136,11 +135,11 @@ public class RoundControl {
* Create a new RoundControl using the given roundState and view
*
* @param roundState
- * initial round state
+ * initial round state
* @param view
- * view used for user interaction
+ * view used for user interaction
* @param mayPause
- * true when players are allowed to pause
+ * true when players are allowed to pause
*/
protected RoundControl(IRoundState roundState, IView view, boolean mayPause) {
this.roundState = roundState;
@@ -216,7 +215,7 @@ public class RoundControl {
* Sets the current round state
*
* @param state
- * to be set
+ * to be set
*/
protected void setRoundState(IRoundState state) {
roundState = state;
@@ -255,12 +254,11 @@ public class RoundControl {
}
view.getTablePanel().setStoneSets(roundState.getTable().clone());
- view.setCurrentPlayerName(roundState.getActivePlayer()
- .getPlayerSettings().getName());
- view.setCurrentPlayerColor(roundState.getActivePlayer()
- .getPlayerSettings().getColor());
- view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer()
- .getLaidOut());
+ view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
+ .getName());
+ view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()
+ .getColor());
+ view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut());
turnControl = createTurnControl(roundState.getActivePlayer()
.getPlayerSettings().getType());
@@ -296,8 +294,9 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(turnMode);
}
- turnControl.setup(new ITurnControl.TurnInfo(roundState, turnMode,
- mayPause), roundState.getGameSettings(), view);
+ turnControl.setup(
+ new ITurnControl.TurnInfo(roundState, turnMode, mayPause),
+ roundState.getGameSettings(), view);
turnControl.getEndOfTurnEvent().add(
new IListener2<IRoundState, InvalidTurnInfo>() {
@Override
@@ -338,7 +337,7 @@ public class RoundControl {
* Override this
*
* @param turnControl
- * current turn control
+ * current turn control
*/
protected void addTurnControlListeners(ITurnControl turnControl) {
}
@@ -347,7 +346,7 @@ public class RoundControl {
* Creates new turn control of the specified type
*
* @param type
- * of the new turn control
+ * of the new turn control
* @return the new turn control
*/
protected ITurnControl createTurnControl(Type type) {
@@ -361,10 +360,8 @@ public class RoundControl {
protected void deal() {
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));
+ for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
+ hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0));
}
}
@@ -375,7 +372,7 @@ public class RoundControl {
* End the players turn
*
* @param invalidTurnInfo
- * info about the player's last turn
+ * info about the player's last turn
*/
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
@@ -393,16 +390,16 @@ public class RoundControl {
view.setInvalidStoneSets(invalidTurnInfo.getInvalidSets());
switch (invalidTurnInfo.getType()) {
- case INITIAL_MELD_ERROR:
- view.setInitialMeldFirstError();
- break;
- case INVALID_SETS:
- view.setStoneCollectionHidden(true);
- break;
- case NOT_ENOUGH_POINTS:
- view.setInitialMeldError(roundState.getGameSettings()
- .getInitialMeldThreshold());
- break;
+ case INITIAL_MELD_ERROR:
+ view.setInitialMeldFirstError();
+ break;
+ case INVALID_SETS:
+ view.setStoneCollectionHidden(true);
+ break;
+ case NOT_ENOUGH_POINTS:
+ view.setInitialMeldError(roundState.getGameSettings()
+ .getInitialMeldThreshold());
+ break;
}
if (!isHuman) {
@@ -412,8 +409,7 @@ public class RoundControl {
}
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
- view.getPlayerPanel().setTime(
- roundState.getGameSettings().getTotalTime(),
+ view.getPlayerPanel().setTime(roundState.getGameSettings().getTotalTime(),
roundState.getGameSettings().getTotalTime());
nextPlayer();
@@ -501,12 +497,10 @@ public class RoundControl {
stonePoints = playerHand.isInitialMeldPossible(roundState
.getGameSettings()) ? 200 : 100;
} else {
- stonePoints = playerHand.getStonePoints(roundState
- .getGameSettings());
+ stonePoints = playerHand.getStonePoints(roundState.getGameSettings());
}
- bestScore = updateBestScore(bestScore, -stonePoints,
- playerHand.getSize());
+ bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize());
points.add(-stonePoints);
pointSum += stonePoints;
@@ -530,11 +524,11 @@ public class RoundControl {
* (everybody still has stones on hand)
*
* @param bestScore
- * of previous rounds
+ * of previous rounds
* @param stonePoints
- * sum of points still left on hands
+ * sum of points still left on hands
* @param size
- * number of players in game (= size of score list in columns)
+ * number of players in game (= size of score list in columns)
* @return Pair of maximum points and hand size
*/
private static Pair<Integer, Integer> updateBestScore(
@@ -558,10 +552,10 @@ public class RoundControl {
}
/**
- * Redeal stones and restart round if a player was allowed to redeal and
- * chose to do so
+ * Redeal stones and restart round if a player was allowed to redeal and chose
+ * to do so
*/
- private void redeal() {
+ protected void redeal() {
turnControl = null;
for (Connection c : new ArrayList<Connection>(connections)) {
c.remove();