summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/RoundControl.java114
1 files changed, 52 insertions, 62 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index b378430..c15eff7 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -9,7 +9,6 @@ import java.util.Collections;
import java.util.List;
import jrummikub.control.turn.AIControl;
-import jrummikub.control.turn.HumanTurnControl;
import jrummikub.control.turn.ITurnControl;
import jrummikub.control.turn.TurnControlFactory;
import jrummikub.control.turn.TurnMode;
@@ -45,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;
@@ -71,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) {
@@ -119,7 +117,6 @@ public class RoundControl {
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
private Event1<Score> endOfRoundEvent = new Event1<Score>();
protected List<Connection> connections = new ArrayList<Connection>();
- private boolean roundFinished;
private boolean mayPause;
public RoundControl(IRoundState roundState, IView view) {
@@ -130,9 +127,9 @@ public class RoundControl {
* Create a new RoundControl using the given gameState and view
*
* @param roundState
- * initial round state
+ * initial round state
* @param view
- * view used for user interaction
+ * view used for user interaction
*/
protected RoundControl(IRoundState roundState, IView view, boolean mayPause) {
this.roundState = roundState;
@@ -208,7 +205,7 @@ public class RoundControl {
* Sets the current round state
*
* @param state
- * to be set
+ * to be set
*/
protected void setRoundState(IRoundState state) {
roundState = state;
@@ -247,12 +244,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());
@@ -331,7 +327,7 @@ public class RoundControl {
* Override this
*
* @param turnControl
- * current turn control
+ * current turn control
*/
protected void addTurnControlListeners(ITurnControl turnControl) {
}
@@ -340,7 +336,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) {
@@ -354,10 +350,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));
}
}
@@ -368,54 +362,47 @@ 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 wasAI = turnControl instanceof AIControl;
- boolean wasHuman = turnControl instanceof HumanTurnControl;
+ boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
+ .getType() == Type.HUMAN;
turnControl = null;
view.getTablePanel().setStoneSets(invalidTurnInfo.getTable());
if (invalidTurnInfo.getType() != null) {
- if (wasHuman) {
+ if (isHuman) {
view.setBottomPanel(BottomPanelType.INVALID_TURN_PANEL);
}
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 (wasAI) {
+ if (!isHuman) {
nextPlayer();
}
return;
}
- if (roundState.getActivePlayer().getHand().getSize() == 0) {
- endOfRound();
- return;
- }
-
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
view.getPlayerPanel().setTime(roundState.getGameSettings().getTotalTime(),
roundState.getGameSettings().getTotalTime());
- if (wasHuman || wasAI) {
- nextPlayer();
- }
+ nextPlayer();
}
/**
@@ -425,6 +412,12 @@ public class RoundControl {
view.setSelectedStones(Collections.<Stone> emptyList());
view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
view.setStoneCollectionHidden(false);
+
+ if (roundState.getActivePlayer().getHand().getSize() == 0) {
+ endOfRound();
+ return;
+ }
+
if (roundState.getLastPlayer() == null) {
if (roundState.getGameHeap().getSize() == 0) {
roundState.setLastPlayer(roundState.getActivePlayer());
@@ -437,14 +430,14 @@ public class RoundControl {
} else {
if (roundState.getActivePlayer() == roundState.getLastPlayer()) {
endOfRound();
+ return;
} else {
roundState.nextPlayer();
roundState.nextTurn();
}
}
- if (!roundFinished) {
- prepareTurn();
- }
+
+ prepareTurn();
}
/**
@@ -454,7 +447,6 @@ public class RoundControl {
removeListeners();
Score roundScore = score();
endOfRoundEvent.emit(roundScore);
- roundFinished = true;
}
/**
@@ -495,12 +487,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;
@@ -524,11 +514,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(
@@ -552,8 +542,8 @@ 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() {
turnControl = null;