summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/GameControl.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-06-20 03:59:04 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-06-20 03:59:04 +0200
commitf3f8ffe4621e91d33732bba9e103ff790a16c7b3 (patch)
treea4663053ea570c7a077a244de9f4f884294208d1 /src/jrummikub/control/GameControl.java
parente79295f271062f2186c2ce0f9b69f1ddfc964abf (diff)
downloadJRummikub-f3f8ffe4621e91d33732bba9e103ff790a16c7b3.tar
JRummikub-f3f8ffe4621e91d33732bba9e103ff790a16c7b3.zip
Added NetworkGameControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@503 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/GameControl.java')
-rw-r--r--src/jrummikub/control/GameControl.java55
1 files changed, 33 insertions, 22 deletions
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<Connection> connections = new ArrayList<Connection>();
- private GameSettings gameSettings;
- private IView view;
- RoundControl roundControl;
- private GameState gameState;
- private List<Connection> connections = new ArrayList<Connection>();
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<Score>() {
@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);
}