Make starting new rounds on network mode work
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@553 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
d09041304b
commit
5d0d593297
5 changed files with 99 additions and 43 deletions
|
@ -1,10 +1,12 @@
|
|||
package jrummikub.control;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import jrummikub.model.GameSettings;
|
||||
import jrummikub.model.GameState;
|
||||
import jrummikub.model.IPlayer;
|
||||
import jrummikub.model.IRoundState;
|
||||
import jrummikub.model.RoundState;
|
||||
import jrummikub.model.Score;
|
||||
|
@ -33,11 +35,11 @@ public class GameControl {
|
|||
* Constructor
|
||||
*
|
||||
* @param gameSettings
|
||||
* the game settings
|
||||
* the game settings
|
||||
* @param saveControl
|
||||
* the save control
|
||||
* the save control
|
||||
* @param view
|
||||
* the view
|
||||
* the view
|
||||
*/
|
||||
public GameControl(GameSettings gameSettings, SaveControl saveControl,
|
||||
IView view) {
|
||||
|
@ -49,9 +51,8 @@ public class GameControl {
|
|||
gameState = new GameState();
|
||||
saveControl.setGameState(gameState);
|
||||
|
||||
gameState
|
||||
.setFirstRoundFirstPlayer((int) (Math.random() * gameSettings
|
||||
.getPlayerList().size()));
|
||||
gameState.setFirstRoundFirstPlayer((int) (Math.random() * gameSettings
|
||||
.getPlayerList().size()));
|
||||
}
|
||||
|
||||
connections.add(view.getNewRoundEvent().add(new IListener() {
|
||||
|
@ -113,9 +114,9 @@ public class GameControl {
|
|||
* Continues game after loading
|
||||
*
|
||||
* @param gameState
|
||||
* the saved GameState (Players, startplayer, points)
|
||||
* the saved GameState (Players, startplayer, points)
|
||||
* @param roundState
|
||||
* the saved RoundState (activePlayer, Table, heap etc)
|
||||
* the saved RoundState (activePlayer, Table, heap etc)
|
||||
*/
|
||||
public void continueGame(GameState gameState, IRoundState roundState) {
|
||||
this.gameState = gameState;
|
||||
|
@ -161,25 +162,24 @@ public class GameControl {
|
|||
* Prepare a new round by setting start player, adding listeners
|
||||
*
|
||||
* @param roundState
|
||||
* of current round
|
||||
* of current round
|
||||
*/
|
||||
private void prepareRound(IRoundState roundState) {
|
||||
saveControl.setRoundState(roundState);
|
||||
|
||||
if (roundState != null) {
|
||||
roundState.setActivePlayerNumber(gameState
|
||||
.getFirstRoundFirstPlayer() + gameState.getScores().size());
|
||||
roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer()
|
||||
+ gameState.getScores().size());
|
||||
}
|
||||
|
||||
roundControl = createRoundControl(roundState);
|
||||
roundControl.getRoundStateUpdateEvent().add(
|
||||
new IListener1<IRoundState>() {
|
||||
@Override
|
||||
public void handle(IRoundState newState) {
|
||||
gameState = newState.getGameState();
|
||||
gameSettings = newState.getGameSettings();
|
||||
}
|
||||
});
|
||||
roundControl.getRoundStateUpdateEvent().add(new IListener1<IRoundState>() {
|
||||
@Override
|
||||
public void handle(IRoundState newState) {
|
||||
gameState = newState.getGameState();
|
||||
gameSettings = newState.getGameSettings();
|
||||
}
|
||||
});
|
||||
roundControl.getEndOfRoundEvent().add(new IListener1<Score>() {
|
||||
@Override
|
||||
public void handle(Score roundScore) {
|
||||
|
@ -209,7 +209,7 @@ public class GameControl {
|
|||
* Creates a new round control with the specified round state
|
||||
*
|
||||
* @param roundState
|
||||
* for new round control
|
||||
* for new round control
|
||||
* @return the round control
|
||||
*/
|
||||
protected RoundControl createRoundControl(IRoundState roundState) {
|
||||
|
@ -228,7 +228,7 @@ public class GameControl {
|
|||
* Sets the score and default values for saving when round ends
|
||||
*
|
||||
* @param roundScore
|
||||
* score for ended round
|
||||
* score for ended round
|
||||
*/
|
||||
private void endOfRound(Score roundScore) {
|
||||
gameState.getScores().add(roundScore);
|
||||
|
@ -242,17 +242,20 @@ public class GameControl {
|
|||
* Sets score panel visible
|
||||
*/
|
||||
private void showScorePanel() {
|
||||
view.showSidePanel(false);
|
||||
view.setBottomPanel(BottomPanelType.WIN_PANEL);
|
||||
view.getSidePanel().setPlayers(Collections.<IPlayer> emptyList());
|
||||
showWinPanel();
|
||||
|
||||
view.getScorePanel().setPlayers(gameSettings.getPlayerList());
|
||||
view.getScorePanel().setScores(gameState.getScores());
|
||||
view.getScorePanel().setAccumulatedScore(
|
||||
gameState.getAccumulatedScore());
|
||||
view.getScorePanel().setAccumulatedScore(gameState.getAccumulatedScore());
|
||||
view.getScorePanel().update();
|
||||
view.showScorePanel(true);
|
||||
}
|
||||
|
||||
protected void showWinPanel() {
|
||||
view.setBottomPanel(BottomPanelType.WIN_PANEL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exits System without warnings if no game control is active
|
||||
*/
|
||||
|
|
|
@ -7,6 +7,7 @@ import jrummikub.model.GameSettings;
|
|||
import jrummikub.model.IRoundState;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.view.IView;
|
||||
import jrummikub.view.IView.BottomPanelType;
|
||||
|
||||
public class NetworkGameControl extends GameControl {
|
||||
private IConnectionControl connectionControl;
|
||||
|
@ -21,11 +22,11 @@ public class NetworkGameControl extends GameControl {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void startGame() {
|
||||
protected void startRound() {
|
||||
connections.add(connectionControl.getRoundStartEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
startRound();
|
||||
NetworkGameControl.super.startRound();
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -43,4 +44,10 @@ public class NetworkGameControl extends GameControl {
|
|||
protected RoundControl createRoundControl(IRoundState roundState) {
|
||||
return new NetworkRoundControl(roundState, view, connectionControl, host);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void showWinPanel() {
|
||||
view.setBottomPanel(host ? BottomPanelType.WIN_PANEL
|
||||
: BottomPanelType.NETWORK_WIN_PANEL);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue