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 java.util.List;
|
||||||
|
|
||||||
import jrummikub.control.turn.AIControl;
|
import jrummikub.control.turn.AIControl;
|
||||||
import jrummikub.control.turn.HumanTurnControl;
|
|
||||||
import jrummikub.control.turn.ITurnControl;
|
import jrummikub.control.turn.ITurnControl;
|
||||||
import jrummikub.control.turn.TurnControlFactory;
|
import jrummikub.control.turn.TurnControlFactory;
|
||||||
import jrummikub.control.turn.TurnMode;
|
import jrummikub.control.turn.TurnMode;
|
||||||
|
@ -45,20 +44,19 @@ public class RoundControl {
|
||||||
/** There are invalid set(s) on the table */
|
/** There are invalid set(s) on the table */
|
||||||
INVALID_SETS,
|
INVALID_SETS,
|
||||||
/**
|
/**
|
||||||
* The player tried to modify the table without providing the initial
|
* The player tried to modify the table without providing the initial meld
|
||||||
* meld threshold first
|
* threshold first
|
||||||
*/
|
*/
|
||||||
INITIAL_MELD_ERROR,
|
INITIAL_MELD_ERROR,
|
||||||
/**
|
/**
|
||||||
* The player didn't provide enough points for the initial meld
|
* The player didn't provide enough points for the initial meld threshold
|
||||||
* threshold
|
|
||||||
*/
|
*/
|
||||||
NOT_ENOUGH_POINTS
|
NOT_ENOUGH_POINTS
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table, stone sets and type of an invalid turn to allow a user to track
|
* Table, stone sets and type of an invalid turn to allow a user to track his
|
||||||
* his own errors
|
* own errors
|
||||||
*/
|
*/
|
||||||
public static class InvalidTurnInfo implements Serializable {
|
public static class InvalidTurnInfo implements Serializable {
|
||||||
private static final long serialVersionUID = -3591000741414366776L;
|
private static final long serialVersionUID = -3591000741414366776L;
|
||||||
|
@ -119,7 +117,6 @@ public class RoundControl {
|
||||||
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
|
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
|
||||||
private Event1<Score> endOfRoundEvent = new Event1<Score>();
|
private Event1<Score> endOfRoundEvent = new Event1<Score>();
|
||||||
protected List<Connection> connections = new ArrayList<Connection>();
|
protected List<Connection> connections = new ArrayList<Connection>();
|
||||||
private boolean roundFinished;
|
|
||||||
private boolean mayPause;
|
private boolean mayPause;
|
||||||
|
|
||||||
public RoundControl(IRoundState roundState, IView view) {
|
public RoundControl(IRoundState roundState, IView view) {
|
||||||
|
@ -247,12 +244,11 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
view.getTablePanel().setStoneSets(roundState.getTable().clone());
|
view.getTablePanel().setStoneSets(roundState.getTable().clone());
|
||||||
view.setCurrentPlayerName(roundState.getActivePlayer()
|
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
|
||||||
.getPlayerSettings().getName());
|
.getName());
|
||||||
view.setCurrentPlayerColor(roundState.getActivePlayer()
|
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings()
|
||||||
.getPlayerSettings().getColor());
|
.getColor());
|
||||||
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer()
|
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut());
|
||||||
.getLaidOut());
|
|
||||||
|
|
||||||
turnControl = createTurnControl(roundState.getActivePlayer()
|
turnControl = createTurnControl(roundState.getActivePlayer()
|
||||||
.getPlayerSettings().getType());
|
.getPlayerSettings().getType());
|
||||||
|
@ -354,10 +350,8 @@ public class RoundControl {
|
||||||
protected void deal() {
|
protected void deal() {
|
||||||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||||
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
||||||
for (int j = 0; j < roundState.getGameSettings()
|
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) {
|
||||||
.getNumberOfStonesDealt(); j++) {
|
hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0));
|
||||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(0,
|
|
||||||
0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,15 +365,15 @@ public class RoundControl {
|
||||||
* info about the player's last turn
|
* info about the player's last turn
|
||||||
*/
|
*/
|
||||||
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
|
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
|
||||||
boolean wasAI = turnControl instanceof AIControl;
|
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
|
||||||
boolean wasHuman = turnControl instanceof HumanTurnControl;
|
.getType() == Type.HUMAN;
|
||||||
|
|
||||||
turnControl = null;
|
turnControl = null;
|
||||||
|
|
||||||
view.getTablePanel().setStoneSets(invalidTurnInfo.getTable());
|
view.getTablePanel().setStoneSets(invalidTurnInfo.getTable());
|
||||||
|
|
||||||
if (invalidTurnInfo.getType() != null) {
|
if (invalidTurnInfo.getType() != null) {
|
||||||
if (wasHuman) {
|
if (isHuman) {
|
||||||
view.setBottomPanel(BottomPanelType.INVALID_TURN_PANEL);
|
view.setBottomPanel(BottomPanelType.INVALID_TURN_PANEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,25 +392,18 @@ public class RoundControl {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wasAI) {
|
if (!isHuman) {
|
||||||
nextPlayer();
|
nextPlayer();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (roundState.getActivePlayer().getHand().getSize() == 0) {
|
|
||||||
endOfRound();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
|
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
|
||||||
view.getPlayerPanel().setTime(roundState.getGameSettings().getTotalTime(),
|
view.getPlayerPanel().setTime(roundState.getGameSettings().getTotalTime(),
|
||||||
roundState.getGameSettings().getTotalTime());
|
roundState.getGameSettings().getTotalTime());
|
||||||
|
|
||||||
if (wasHuman || wasAI) {
|
|
||||||
nextPlayer();
|
nextPlayer();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the next player as active player if the round is not finished
|
* 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.setSelectedStones(Collections.<Stone> emptyList());
|
||||||
view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
|
view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
|
||||||
view.setStoneCollectionHidden(false);
|
view.setStoneCollectionHidden(false);
|
||||||
|
|
||||||
|
if (roundState.getActivePlayer().getHand().getSize() == 0) {
|
||||||
|
endOfRound();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (roundState.getLastPlayer() == null) {
|
if (roundState.getLastPlayer() == null) {
|
||||||
if (roundState.getGameHeap().getSize() == 0) {
|
if (roundState.getGameHeap().getSize() == 0) {
|
||||||
roundState.setLastPlayer(roundState.getActivePlayer());
|
roundState.setLastPlayer(roundState.getActivePlayer());
|
||||||
|
@ -437,15 +430,15 @@ public class RoundControl {
|
||||||
} else {
|
} else {
|
||||||
if (roundState.getActivePlayer() == roundState.getLastPlayer()) {
|
if (roundState.getActivePlayer() == roundState.getLastPlayer()) {
|
||||||
endOfRound();
|
endOfRound();
|
||||||
|
return;
|
||||||
} else {
|
} else {
|
||||||
roundState.nextPlayer();
|
roundState.nextPlayer();
|
||||||
roundState.nextTurn();
|
roundState.nextTurn();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!roundFinished) {
|
|
||||||
prepareTurn();
|
prepareTurn();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ends the current round and emits an event setting the score
|
* Ends the current round and emits an event setting the score
|
||||||
|
@ -454,7 +447,6 @@ public class RoundControl {
|
||||||
removeListeners();
|
removeListeners();
|
||||||
Score roundScore = score();
|
Score roundScore = score();
|
||||||
endOfRoundEvent.emit(roundScore);
|
endOfRoundEvent.emit(roundScore);
|
||||||
roundFinished = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -495,12 +487,10 @@ public class RoundControl {
|
||||||
stonePoints = playerHand.isInitialMeldPossible(roundState
|
stonePoints = playerHand.isInitialMeldPossible(roundState
|
||||||
.getGameSettings()) ? 200 : 100;
|
.getGameSettings()) ? 200 : 100;
|
||||||
} else {
|
} else {
|
||||||
stonePoints = playerHand.getStonePoints(roundState
|
stonePoints = playerHand.getStonePoints(roundState.getGameSettings());
|
||||||
.getGameSettings());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bestScore = updateBestScore(bestScore, -stonePoints,
|
bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize());
|
||||||
playerHand.getSize());
|
|
||||||
|
|
||||||
points.add(-stonePoints);
|
points.add(-stonePoints);
|
||||||
pointSum += stonePoints;
|
pointSum += stonePoints;
|
||||||
|
@ -552,8 +542,8 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redeal stones and restart round if a player was allowed to redeal and
|
* Redeal stones and restart round if a player was allowed to redeal and chose
|
||||||
* chose to do so
|
* to do so
|
||||||
*/
|
*/
|
||||||
private void redeal() {
|
private void redeal() {
|
||||||
turnControl = null;
|
turnControl = null;
|
||||||
|
|
Reference in a new issue