summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/GameControl.java
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-06-21 13:47:15 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-06-21 13:47:15 +0200
commit5e3ce21569f5adc92c969735c88af488cf581916 (patch)
tree08216e061937a4672fffefcf1054caadb92b568e /src/jrummikub/control/GameControl.java
parentfcd7af76285a58aa8e2ba645b8380c2c86f66908 (diff)
downloadJRummikub-5e3ce21569f5adc92c969735c88af488cf581916.tar
JRummikub-5e3ce21569f5adc92c969735c88af488cf581916.zip
Das reine control-package ist vollständig kommentiert
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@545 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/GameControl.java')
-rw-r--r--src/jrummikub/control/GameControl.java79
1 files changed, 62 insertions, 17 deletions
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java
index c038f9a..736e440 100644
--- a/src/jrummikub/control/GameControl.java
+++ b/src/jrummikub/control/GameControl.java
@@ -33,11 +33,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,8 +49,9 @@ 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() {
@@ -84,11 +85,17 @@ public class GameControl {
return endOfGameEvent;
}
+ /**
+ * Ends the running game
+ */
private void endGame() {
removeListeners();
endOfGameEvent.emit();
}
+ /**
+ * Removes all listeners from the connection
+ */
private void removeListeners() {
for (Connection c : connections) {
c.remove();
@@ -106,9 +113,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;
@@ -135,6 +142,9 @@ public class GameControl {
view.clearView();
}
+ /**
+ * Start a new round within the existing game
+ */
protected void startRound() {
if (roundControl != null) {
return;
@@ -147,22 +157,29 @@ public class GameControl {
roundControl.startRound();
}
+ /**
+ * Prepare a new round by setting start player, adding listeners
+ *
+ * @param roundState
+ * 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) {
@@ -179,19 +196,40 @@ public class GameControl {
});
}
+ /**
+ * Creates a new round State
+ *
+ * @return the round state
+ */
protected IRoundState createRoundState() {
return new RoundState(gameSettings, gameState);
}
+ /**
+ * Creates a new round control with the specified round state
+ *
+ * @param roundState
+ * for new round control
+ * @return the round control
+ */
protected RoundControl createRoundControl(IRoundState roundState) {
return new RoundControl(roundState, view);
}
+ /**
+ * Restarts round after loading
+ */
private void restartRound() {
roundControl = null;
startRound();
}
+ /**
+ * Sets the score and default values for saving when round ends
+ *
+ * @param roundScore
+ * score for ended round
+ */
private void endOfRound(Score roundScore) {
gameState.getScores().add(roundScore);
saveControl.setRoundState(null);
@@ -200,17 +238,24 @@ public class GameControl {
showScorePanel();
}
+ /**
+ * Sets score panel visible
+ */
private void showScorePanel() {
view.showSidePanel(false);
view.setBottomPanel(BottomPanelType.WIN_PANEL);
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);
}
+ /**
+ * Exits System without warnings if no game control is active
+ */
private void endProgram() {
System.exit(0);
}