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() {
|
||||
roundControl = null;
|
||||
|
|
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
|
|
@ -107,6 +107,7 @@ public class ConnectionControl implements IConnectionControl {
|
|||
|
||||
private Event gameStartEvent = new Event();
|
||||
private Event roundStartEvent = new Event();
|
||||
private Event redealEvent = new Event();
|
||||
private Event1<IRoundState> roundStateUpdateEvent = new Event1<IRoundState>();
|
||||
|
||||
private Event1<ITable> tableUpdateEvent = new Event1<ITable>();
|
||||
|
@ -220,6 +221,11 @@ public class ConnectionControl implements IConnectionControl {
|
|||
return roundStartEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent getRedealEvent() {
|
||||
return redealEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEvent1<IRoundState> getRoundStateUpdateEvent() {
|
||||
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
|
||||
public void updateRoundState(final IRoundState roundState) {
|
||||
final UUID uuid = currentGame.getGameID();
|
||||
|
@ -541,7 +559,16 @@ public class ConnectionControl implements IConnectionControl {
|
|||
gameStartEvent.emit();
|
||||
} else if (messageType.equals("round_start")) {
|
||||
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
|
||||
.getValue("state"));
|
||||
fixGameSettings(state.getGameSettings());
|
||||
|
|
|
@ -40,6 +40,8 @@ interface IConnectionControl {
|
|||
|
||||
public IEvent getRoundStartEvent();
|
||||
|
||||
public IEvent getRedealEvent();
|
||||
|
||||
public IEvent1<IRoundState> getRoundStateUpdateEvent();
|
||||
|
||||
public IEvent1<ITable> getTableUpdateEvent();
|
||||
|
@ -70,6 +72,8 @@ interface IConnectionControl {
|
|||
|
||||
public void startRound();
|
||||
|
||||
public void redeal();
|
||||
|
||||
public void updateRoundState(IRoundState roundState);
|
||||
|
||||
public void updateTable(ITable table);
|
||||
|
|
|
@ -102,4 +102,13 @@ public class NetworkRoundControl extends RoundControl {
|
|||
|
||||
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.util.Event1;
|
||||
import jrummikub.util.IEvent1;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.IListener1;
|
||||
import jrummikub.util.IListener2;
|
||||
|
||||
|
@ -37,6 +38,12 @@ public class NetworkTurnControl extends AbstractTurnControl {
|
|||
endOfTurn(state, invalidTurnInfo);
|
||||
}
|
||||
}));
|
||||
connections.add(connectionControl.getRedealEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
redeal();
|
||||
}
|
||||
}));
|
||||
|
||||
timer.startTimer();
|
||||
}
|
||||
|
@ -47,6 +54,12 @@ public class NetworkTurnControl extends AbstractTurnControl {
|
|||
endOfTurnEvent.emit(roundState, invalidTurnInfo);
|
||||
}
|
||||
|
||||
private void redeal() {
|
||||
cleanUp();
|
||||
|
||||
redealEvent.emit();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void timeOut() {
|
||||
}
|
||||
|
|
Reference in a new issue