From f3f8ffe4621e91d33732bba9e103ff790a16c7b3 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 20 Jun 2011 03:59:04 +0200 Subject: Added NetworkGameControl git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@503 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/GameControl.java | 55 ++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 22 deletions(-) (limited to 'src/jrummikub/control/GameControl.java') diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java index 66a96b6..ead4c51 100644 --- a/src/jrummikub/control/GameControl.java +++ b/src/jrummikub/control/GameControl.java @@ -20,24 +20,24 @@ import jrummikub.view.IView.BottomPanelType; * Controls a Game, at some point including all Rounds, starts new Rounds */ public class GameControl { - private SaveControl saveControl; + protected SaveControl saveControl; + protected GameSettings gameSettings; + protected IView view; + protected RoundControl roundControl; + protected GameState gameState; + protected List connections = new ArrayList(); - private GameSettings gameSettings; - private IView view; - RoundControl roundControl; - private GameState gameState; - private List connections = new ArrayList(); private Event endOfGameEvent = new Event(); /** * 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) { @@ -45,11 +45,13 @@ public class GameControl { this.saveControl = saveControl; this.view = view; - gameState = new GameState(); - saveControl.setGameState(gameState); + if (gameSettings != null) { + 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() { @Override @@ -104,9 +106,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; @@ -133,14 +135,14 @@ public class GameControl { view.clearView(); } - private void startRound() { + protected void startRound() { if (roundControl != null) { return; } view.showScorePanel(false); - IRoundState roundState = new RoundState(gameSettings); + IRoundState roundState = createRoundState(); prepareRound(roundState); roundControl.startRound(); } @@ -148,10 +150,12 @@ public class GameControl { private void prepareRound(IRoundState roundState) { saveControl.setRoundState(roundState); - roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer() - + gameState.getScores().size()); + if (roundState != null) { + roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer() + + gameState.getScores().size()); + } - roundControl = new RoundControl(roundState, view); + roundControl = createRoundControl(roundState); roundControl.getEndOfRoundEvent().add(new IListener1() { @Override @@ -169,6 +173,14 @@ public class GameControl { }); } + protected IRoundState createRoundState() { + return new RoundState(gameSettings, gameState); + } + + protected RoundControl createRoundControl(IRoundState roundState) { + return new RoundControl(roundState, view); + } + private void restartRound() { roundControl = null; startRound(); @@ -188,8 +200,7 @@ public class GameControl { 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); } -- cgit v1.2.3