Fix redealing in network mode
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@554 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
5d0d593297
commit
6acf9d6078
6 changed files with 101 additions and 54 deletions
|
@ -217,7 +217,7 @@ public class GameControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restarts round after loading
|
* Restarts round after redealing
|
||||||
*/
|
*/
|
||||||
private void restartRound() {
|
private void restartRound() {
|
||||||
roundControl = null;
|
roundControl = null;
|
||||||
|
|
|
@ -44,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;
|
||||||
|
@ -70,11 +69,11 @@ public class RoundControl {
|
||||||
* Creates new InvalidTurnInfo
|
* Creates new InvalidTurnInfo
|
||||||
*
|
*
|
||||||
* @param table
|
* @param table
|
||||||
* the table after the turn
|
* the table after the turn
|
||||||
* @param type
|
* @param type
|
||||||
* the type of the invalid turn
|
* the type of the invalid turn
|
||||||
* @param invalidSets
|
* @param invalidSets
|
||||||
* the sets causing the turn to be invalid
|
* the sets causing the turn to be invalid
|
||||||
*/
|
*/
|
||||||
public InvalidTurnInfo(ITable table, InvalidTurnType type,
|
public InvalidTurnInfo(ITable table, InvalidTurnType type,
|
||||||
Collection<StoneSet> invalidSets) {
|
Collection<StoneSet> invalidSets) {
|
||||||
|
@ -124,9 +123,9 @@ public class RoundControl {
|
||||||
* Create a new RoundControl using the given roundState and view
|
* Create a new RoundControl using the given roundState and view
|
||||||
*
|
*
|
||||||
* @param roundState
|
* @param roundState
|
||||||
* initial round state
|
* initial round state
|
||||||
* @param view
|
* @param view
|
||||||
* view used for user interaction
|
* view used for user interaction
|
||||||
*/
|
*/
|
||||||
public RoundControl(IRoundState roundState, IView view) {
|
public RoundControl(IRoundState roundState, IView view) {
|
||||||
this(roundState, view, true);
|
this(roundState, view, true);
|
||||||
|
@ -136,11 +135,11 @@ public class RoundControl {
|
||||||
* Create a new RoundControl using the given roundState and view
|
* Create a new RoundControl using the given roundState and view
|
||||||
*
|
*
|
||||||
* @param roundState
|
* @param roundState
|
||||||
* initial round state
|
* initial round state
|
||||||
* @param view
|
* @param view
|
||||||
* view used for user interaction
|
* view used for user interaction
|
||||||
* @param mayPause
|
* @param mayPause
|
||||||
* true when players are allowed to pause
|
* true when players are allowed to pause
|
||||||
*/
|
*/
|
||||||
protected RoundControl(IRoundState roundState, IView view, boolean mayPause) {
|
protected RoundControl(IRoundState roundState, IView view, boolean mayPause) {
|
||||||
this.roundState = roundState;
|
this.roundState = roundState;
|
||||||
|
@ -216,7 +215,7 @@ public class RoundControl {
|
||||||
* Sets the current round state
|
* Sets the current round state
|
||||||
*
|
*
|
||||||
* @param state
|
* @param state
|
||||||
* to be set
|
* to be set
|
||||||
*/
|
*/
|
||||||
protected void setRoundState(IRoundState state) {
|
protected void setRoundState(IRoundState state) {
|
||||||
roundState = state;
|
roundState = state;
|
||||||
|
@ -255,12 +254,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());
|
||||||
|
@ -296,8 +294,9 @@ public class RoundControl {
|
||||||
view.getPlayerPanel().setEndTurnMode(turnMode);
|
view.getPlayerPanel().setEndTurnMode(turnMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
turnControl.setup(new ITurnControl.TurnInfo(roundState, turnMode,
|
turnControl.setup(
|
||||||
mayPause), roundState.getGameSettings(), view);
|
new ITurnControl.TurnInfo(roundState, turnMode, mayPause),
|
||||||
|
roundState.getGameSettings(), view);
|
||||||
turnControl.getEndOfTurnEvent().add(
|
turnControl.getEndOfTurnEvent().add(
|
||||||
new IListener2<IRoundState, InvalidTurnInfo>() {
|
new IListener2<IRoundState, InvalidTurnInfo>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -338,7 +337,7 @@ public class RoundControl {
|
||||||
* Override this
|
* Override this
|
||||||
*
|
*
|
||||||
* @param turnControl
|
* @param turnControl
|
||||||
* current turn control
|
* current turn control
|
||||||
*/
|
*/
|
||||||
protected void addTurnControlListeners(ITurnControl turnControl) {
|
protected void addTurnControlListeners(ITurnControl turnControl) {
|
||||||
}
|
}
|
||||||
|
@ -347,7 +346,7 @@ public class RoundControl {
|
||||||
* Creates new turn control of the specified type
|
* Creates new turn control of the specified type
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* of the new turn control
|
* of the new turn control
|
||||||
* @return the new turn control
|
* @return the new turn control
|
||||||
*/
|
*/
|
||||||
protected ITurnControl createTurnControl(Type type) {
|
protected ITurnControl createTurnControl(Type type) {
|
||||||
|
@ -361,10 +360,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));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -375,7 +372,7 @@ public class RoundControl {
|
||||||
* End the players turn
|
* End the players turn
|
||||||
*
|
*
|
||||||
* @param invalidTurnInfo
|
* @param invalidTurnInfo
|
||||||
* 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 isHuman = roundState.getActivePlayer().getPlayerSettings()
|
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
|
||||||
|
@ -393,16 +390,16 @@ public class RoundControl {
|
||||||
view.setInvalidStoneSets(invalidTurnInfo.getInvalidSets());
|
view.setInvalidStoneSets(invalidTurnInfo.getInvalidSets());
|
||||||
|
|
||||||
switch (invalidTurnInfo.getType()) {
|
switch (invalidTurnInfo.getType()) {
|
||||||
case INITIAL_MELD_ERROR:
|
case INITIAL_MELD_ERROR:
|
||||||
view.setInitialMeldFirstError();
|
view.setInitialMeldFirstError();
|
||||||
break;
|
break;
|
||||||
case INVALID_SETS:
|
case INVALID_SETS:
|
||||||
view.setStoneCollectionHidden(true);
|
view.setStoneCollectionHidden(true);
|
||||||
break;
|
break;
|
||||||
case NOT_ENOUGH_POINTS:
|
case NOT_ENOUGH_POINTS:
|
||||||
view.setInitialMeldError(roundState.getGameSettings()
|
view.setInitialMeldError(roundState.getGameSettings()
|
||||||
.getInitialMeldThreshold());
|
.getInitialMeldThreshold());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isHuman) {
|
if (!isHuman) {
|
||||||
|
@ -412,8 +409,7 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
|
view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL);
|
||||||
view.getPlayerPanel().setTime(
|
view.getPlayerPanel().setTime(roundState.getGameSettings().getTotalTime(),
|
||||||
roundState.getGameSettings().getTotalTime(),
|
|
||||||
roundState.getGameSettings().getTotalTime());
|
roundState.getGameSettings().getTotalTime());
|
||||||
|
|
||||||
nextPlayer();
|
nextPlayer();
|
||||||
|
@ -501,12 +497,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;
|
||||||
|
@ -530,11 +524,11 @@ public class RoundControl {
|
||||||
* (everybody still has stones on hand)
|
* (everybody still has stones on hand)
|
||||||
*
|
*
|
||||||
* @param bestScore
|
* @param bestScore
|
||||||
* of previous rounds
|
* of previous rounds
|
||||||
* @param stonePoints
|
* @param stonePoints
|
||||||
* sum of points still left on hands
|
* sum of points still left on hands
|
||||||
* @param size
|
* @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
|
* @return Pair of maximum points and hand size
|
||||||
*/
|
*/
|
||||||
private static Pair<Integer, Integer> updateBestScore(
|
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
|
* Redeal stones and restart round if a player was allowed to redeal and chose
|
||||||
* chose to do so
|
* to do so
|
||||||
*/
|
*/
|
||||||
private void redeal() {
|
protected void redeal() {
|
||||||
turnControl = null;
|
turnControl = null;
|
||||||
for (Connection c : new ArrayList<Connection>(connections)) {
|
for (Connection c : new ArrayList<Connection>(connections)) {
|
||||||
c.remove();
|
c.remove();
|
||||||
|
|
|
@ -107,6 +107,7 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
|
|
||||||
private Event gameStartEvent = new Event();
|
private Event gameStartEvent = new Event();
|
||||||
private Event roundStartEvent = new Event();
|
private Event roundStartEvent = new Event();
|
||||||
|
private Event redealEvent = new Event();
|
||||||
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
|
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
|
||||||
|
|
||||||
private Event1<ITable> tableUpdateEvent = new Event1<ITable>();
|
private Event1<ITable> tableUpdateEvent = new Event1<ITable>();
|
||||||
|
@ -220,6 +221,11 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
return roundStartEvent;
|
return roundStartEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent getRedealEvent() {
|
||||||
|
return redealEvent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent1<IRoundState> getRoundStateUpdateEvent() {
|
public IEvent1<IRoundState> getRoundStateUpdateEvent() {
|
||||||
return roundStateUpdateEvent;
|
return roundStateUpdateEvent;
|
||||||
|
@ -367,6 +373,18 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void redeal() {
|
||||||
|
final UUID uuid = currentGame.getGameID();
|
||||||
|
run(new SendRunner() {
|
||||||
|
@Override
|
||||||
|
protected void addData(DefaultPacketExtension extension) {
|
||||||
|
extension.setValue("messageType", "redeal");
|
||||||
|
extension.setValue("uuid", uuid.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateRoundState(final IRoundState roundState) {
|
public void updateRoundState(final IRoundState roundState) {
|
||||||
final UUID uuid = currentGame.getGameID();
|
final UUID uuid = currentGame.getGameID();
|
||||||
|
@ -541,7 +559,16 @@ public class ConnectionControl implements IConnectionControl {
|
||||||
gameStartEvent.emit();
|
gameStartEvent.emit();
|
||||||
} else if (messageType.equals("round_start")) {
|
} else if (messageType.equals("round_start")) {
|
||||||
roundStartEvent.emit();
|
roundStartEvent.emit();
|
||||||
} else if (messageType.equals("round_state_update")) {
|
} else if (messageType.equals("redeal")) {
|
||||||
|
redealEvent.emit();
|
||||||
|
} else {
|
||||||
|
messagesDuringRound(extension, messageType);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void messagesDuringRound(DefaultPacketExtension extension,
|
||||||
|
String messageType) {
|
||||||
|
if (messageType.equals("round_state_update")) {
|
||||||
IRoundState state = (IRoundState) Base64.decodeToObject(extension
|
IRoundState state = (IRoundState) Base64.decodeToObject(extension
|
||||||
.getValue("state"));
|
.getValue("state"));
|
||||||
fixGameSettings(state.getGameSettings());
|
fixGameSettings(state.getGameSettings());
|
||||||
|
|
|
@ -40,6 +40,8 @@ interface IConnectionControl {
|
||||||
|
|
||||||
public IEvent getRoundStartEvent();
|
public IEvent getRoundStartEvent();
|
||||||
|
|
||||||
|
public IEvent getRedealEvent();
|
||||||
|
|
||||||
public IEvent1<IRoundState> getRoundStateUpdateEvent();
|
public IEvent1<IRoundState> getRoundStateUpdateEvent();
|
||||||
|
|
||||||
public IEvent1<ITable> getTableUpdateEvent();
|
public IEvent1<ITable> getTableUpdateEvent();
|
||||||
|
@ -70,6 +72,8 @@ interface IConnectionControl {
|
||||||
|
|
||||||
public void startRound();
|
public void startRound();
|
||||||
|
|
||||||
|
public void redeal();
|
||||||
|
|
||||||
public void updateRoundState(IRoundState roundState);
|
public void updateRoundState(IRoundState roundState);
|
||||||
|
|
||||||
public void updateTable(ITable table);
|
public void updateTable(ITable table);
|
||||||
|
|
|
@ -102,4 +102,13 @@ public class NetworkRoundControl extends RoundControl {
|
||||||
|
|
||||||
super.endOfTurn(invalidTurnInfo);
|
super.endOfTurn(invalidTurnInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void redeal() {
|
||||||
|
if (currentlyActive) {
|
||||||
|
connectionControl.redeal();
|
||||||
|
}
|
||||||
|
|
||||||
|
super.redeal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import jrummikub.model.IRoundState;
|
||||||
import jrummikub.model.ITable;
|
import jrummikub.model.ITable;
|
||||||
import jrummikub.util.Event1;
|
import jrummikub.util.Event1;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.util.IListener1;
|
import jrummikub.util.IListener1;
|
||||||
import jrummikub.util.IListener2;
|
import jrummikub.util.IListener2;
|
||||||
|
|
||||||
|
@ -37,6 +38,12 @@ public class NetworkTurnControl extends AbstractTurnControl {
|
||||||
endOfTurn(state, invalidTurnInfo);
|
endOfTurn(state, invalidTurnInfo);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
connections.add(connectionControl.getRedealEvent().add(new IListener() {
|
||||||
|
@Override
|
||||||
|
public void handle() {
|
||||||
|
redeal();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
timer.startTimer();
|
timer.startTimer();
|
||||||
}
|
}
|
||||||
|
@ -47,6 +54,12 @@ public class NetworkTurnControl extends AbstractTurnControl {
|
||||||
endOfTurnEvent.emit(roundState, invalidTurnInfo);
|
endOfTurnEvent.emit(roundState, invalidTurnInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void redeal() {
|
||||||
|
cleanUp();
|
||||||
|
|
||||||
|
redealEvent.emit();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void timeOut() {
|
protected void timeOut() {
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue