From 5e3ce21569f5adc92c969735c88af488cf581916 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Tue, 21 Jun 2011 13:47:15 +0200 Subject: =?UTF-8?q?Das=20reine=20control-package=20ist=20vollst=C3=A4ndig?= =?UTF-8?q?=20kommentiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@545 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/GameControl.java | 79 ++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 17 deletions(-) (limited to 'src/jrummikub/control/GameControl.java') 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() { - @Override - public void handle(IRoundState newState) { - gameState = newState.getGameState(); - gameSettings = newState.getGameSettings(); - } - }); + roundControl.getRoundStateUpdateEvent().add( + new IListener1() { + @Override + public void handle(IRoundState newState) { + gameState = newState.getGameState(); + gameSettings = newState.getGameSettings(); + } + }); roundControl.getEndOfRoundEvent().add(new IListener1() { @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); } -- cgit v1.2.3