Don't duplicate round scores in network games
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@549 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
39ba50e1ac
commit
81de4ad99f
1 changed files with 52 additions and 62 deletions
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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());
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -371,15 +365,15 @@ public class RoundControl {
|
|||
* 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);
|
||||
}
|
||||
|
||||
|
@ -398,25 +392,18 @@ public class RoundControl {
|
|||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the next player as active player if the round is not finished
|
||||
|
@ -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,15 +430,15 @@ public class RoundControl {
|
|||
} else {
|
||||
if (roundState.getActivePlayer() == roundState.getLastPlayer()) {
|
||||
endOfRound();
|
||||
return;
|
||||
} else {
|
||||
roundState.nextPlayer();
|
||||
roundState.nextTurn();
|
||||
}
|
||||
}
|
||||
if (!roundFinished) {
|
||||
|
||||
prepareTurn();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the current round and emits an event setting the score
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
|
Reference in a new issue