From d09041304bee53b86c3ddd098a6ff39db85889f3 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 21 Jun 2011 18:51:23 +0200 Subject: Fixed some comment and metrics warnings git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@552 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/ApplicationControl.java | 102 ++++++++++++++------------ src/jrummikub/control/LoginControl.java | 19 +++-- src/jrummikub/control/RoundControl.java | 102 +++++++++++++++----------- src/jrummikub/control/turn/ITurnControl.java | 30 ++++++-- 4 files changed, 148 insertions(+), 105 deletions(-) (limited to 'src/jrummikub/control') diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index 58d1690..7f5cf6d 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -38,22 +38,41 @@ public class ApplicationControl { this.view = view; saveControl = new SaveControl(view); + addQuitGameHandlers(); + + view.getNetworkGameEvent().add(new IListener() { + @Override + public void handle() { + abortControls(); + + createLoginControl(true); + } + }); + + saveControl.getLoadEvent().add( + new IListener3() { + @Override + public void handle(GameSettings settings, GameState gameState, + IRoundState roundState) { + abortControls(); + gameControl = new GameControl(settings, saveControl, view); + addGameControlListeners(gameControl); + gameControl.continueGame(gameState, roundState); + } + }); + saveControl.getLoadErrorEvent().add(new IListener() { + @Override + public void handle() { + view.showLoadingError(); + } + }); + } + + private void addQuitGameHandlers() { view.getMenuNewGameEvent().add(new IListener() { @Override public void handle() { - view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME); - view.showQuitWarningPanel(true); - tempConnection = view.getQuitWarningPanel().getQuitEvent() - .add(new IListener() { - @Override - public void handle() { - abortControls(); - startApplication(); - view.showQuitWarningPanel(false); - tempConnection.remove(); - tempConnection = null; - } - }); + showRestartWarning(); } }); view.getQuitEvent().add(new IListener() { @@ -62,23 +81,13 @@ public class ApplicationControl { if (networkControl != null) { return; } - if (gameControl == null) { System.exit(0); } else { - view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS); - view.showQuitWarningPanel(true); - tempConnection = view.getQuitWarningPanel().getQuitEvent() - .add(new IListener() { - @Override - public void handle() { - System.exit(0); - } - }); + showQuitWarning(); } } }); - view.getQuitWarningPanel().getCancelEvent().add(new IListener() { @Override public void handle() { @@ -89,33 +98,34 @@ public class ApplicationControl { } } }); + } - view.getNetworkGameEvent().add(new IListener() { - @Override - public void handle() { - abortControls(); - - createLoginControl(true); - } - }); - - saveControl.getLoadEvent().add( - new IListener3() { + private void showRestartWarning() { + view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME); + view.showQuitWarningPanel(true); + tempConnection = view.getQuitWarningPanel().getQuitEvent() + .add(new IListener() { @Override - public void handle(GameSettings settings, GameState gameState, - IRoundState roundState) { + public void handle() { abortControls(); - gameControl = new GameControl(settings, saveControl, view); - addGameControlListeners(gameControl); - gameControl.continueGame(gameState, roundState); + startApplication(); + view.showQuitWarningPanel(false); + tempConnection.remove(); + tempConnection = null; + } + }); + } + + private void showQuitWarning() { + view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS); + view.showQuitWarningPanel(true); + tempConnection = view.getQuitWarningPanel().getQuitEvent() + .add(new IListener() { + @Override + public void handle() { + System.exit(0); } }); - saveControl.getLoadErrorEvent().add(new IListener() { - @Override - public void handle() { - view.showLoadingError(); - } - }); } /** diff --git a/src/jrummikub/control/LoginControl.java b/src/jrummikub/control/LoginControl.java index 24bfcf6..8908c0d 100644 --- a/src/jrummikub/control/LoginControl.java +++ b/src/jrummikub/control/LoginControl.java @@ -27,7 +27,7 @@ public class LoginControl { * Constructor for login Control * * @param view - * for events which need handling + * for events which need handling */ public LoginControl(final IView view) { this.view = view; @@ -40,18 +40,21 @@ public class LoginControl { } })); - connections.add(view.getLoginPanel().getCancelEvent().add(new IListener() { - @Override - public void handle() { - abort(); - cancelEvent.emit(); - } - })); + connections.add(view.getLoginPanel().getCancelEvent() + .add(new IListener() { + @Override + public void handle() { + abort(); + cancelEvent.emit(); + } + })); } /** * Open Login panel * + * @param reset + * when true resets the information in the login panel */ public void startLogin(boolean reset) { if (reset) { diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index c15eff7..7f3135a 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -44,19 +44,20 @@ public class RoundControl { /** There are invalid set(s) on the table */ INVALID_SETS, /** - * The player tried to modify the table without providing the initial meld - * threshold first + * The player tried to modify the table without providing the initial + * meld threshold first */ INITIAL_MELD_ERROR, /** - * The player didn't provide enough points for the initial meld threshold + * The player didn't provide enough points for the initial meld + * threshold */ NOT_ENOUGH_POINTS } /** - * Table, stone sets and type of an invalid turn to allow a user to track his - * own errors + * Table, stone sets and type of an invalid turn to allow a user to track + * his own errors */ public static class InvalidTurnInfo implements Serializable { private static final long serialVersionUID = -3591000741414366776L; @@ -69,11 +70,11 @@ public class RoundControl { * Creates new InvalidTurnInfo * * @param table - * the table after the turn + * the table after the turn * @param type - * the type of the invalid turn + * the type of the invalid turn * @param invalidSets - * the sets causing the turn to be invalid + * the sets causing the turn to be invalid */ public InvalidTurnInfo(ITable table, InvalidTurnType type, Collection invalidSets) { @@ -119,17 +120,27 @@ public class RoundControl { protected List connections = new ArrayList(); private boolean mayPause; + /** + * Create a new RoundControl using the given roundState and view + * + * @param roundState + * initial round state + * @param view + * view used for user interaction + */ public RoundControl(IRoundState roundState, IView view) { this(roundState, view, true); } /** - * Create a new RoundControl using the given gameState and view + * Create a new RoundControl using the given roundState and view * * @param roundState - * initial round state + * initial round state * @param view - * view used for user interaction + * view used for user interaction + * @param mayPause + * true when players are allowed to pause */ protected RoundControl(IRoundState roundState, IView view, boolean mayPause) { this.roundState = roundState; @@ -205,7 +216,7 @@ public class RoundControl { * Sets the current round state * * @param state - * to be set + * to be set */ protected void setRoundState(IRoundState state) { roundState = state; @@ -244,11 +255,12 @@ public class RoundControl { } view.getTablePanel().setStoneSets(roundState.getTable().clone()); - view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() - .getName()); - view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() - .getColor()); - view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut()); + view.setCurrentPlayerName(roundState.getActivePlayer() + .getPlayerSettings().getName()); + view.setCurrentPlayerColor(roundState.getActivePlayer() + .getPlayerSettings().getColor()); + view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer() + .getLaidOut()); turnControl = createTurnControl(roundState.getActivePlayer() .getPlayerSettings().getType()); @@ -284,9 +296,8 @@ public class RoundControl { view.getPlayerPanel().setEndTurnMode(turnMode); } - turnControl.setup( - new ITurnControl.TurnInfo(roundState, turnMode, mayPause), - roundState.getGameSettings(), view); + turnControl.setup(new ITurnControl.TurnInfo(roundState, turnMode, + mayPause), roundState.getGameSettings(), view); turnControl.getEndOfTurnEvent().add( new IListener2() { @Override @@ -327,7 +338,7 @@ public class RoundControl { * Override this * * @param turnControl - * current turn control + * current turn control */ protected void addTurnControlListeners(ITurnControl turnControl) { } @@ -336,7 +347,7 @@ public class RoundControl { * Creates new turn control of the specified type * * @param type - * of the new turn control + * of the new turn control * @return the new turn control */ protected ITurnControl createTurnControl(Type type) { @@ -350,8 +361,10 @@ public class RoundControl { protected void deal() { for (int i = 0; i < roundState.getPlayerCount(); i++) { IHand hand = roundState.getNthNextPlayer(i).getHand(); - for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) { - hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0)); + for (int j = 0; j < roundState.getGameSettings() + .getNumberOfStonesDealt(); j++) { + hand.drop(roundState.getGameHeap().drawStone(), new Position(0, + 0)); } } @@ -362,7 +375,7 @@ public class RoundControl { * End the players turn * * @param invalidTurnInfo - * info about the player's last turn + * info about the player's last turn */ protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) { boolean isHuman = roundState.getActivePlayer().getPlayerSettings() @@ -380,16 +393,16 @@ public class RoundControl { view.setInvalidStoneSets(invalidTurnInfo.getInvalidSets()); switch (invalidTurnInfo.getType()) { - case INITIAL_MELD_ERROR: - view.setInitialMeldFirstError(); - break; - case INVALID_SETS: - view.setStoneCollectionHidden(true); - break; - case NOT_ENOUGH_POINTS: - view.setInitialMeldError(roundState.getGameSettings() - .getInitialMeldThreshold()); - break; + case INITIAL_MELD_ERROR: + view.setInitialMeldFirstError(); + break; + case INVALID_SETS: + view.setStoneCollectionHidden(true); + break; + case NOT_ENOUGH_POINTS: + view.setInitialMeldError(roundState.getGameSettings() + .getInitialMeldThreshold()); + break; } if (!isHuman) { @@ -399,7 +412,8 @@ public class RoundControl { } view.setBottomPanel(BottomPanelType.NONHUMAN_HAND_PANEL); - view.getPlayerPanel().setTime(roundState.getGameSettings().getTotalTime(), + view.getPlayerPanel().setTime( + roundState.getGameSettings().getTotalTime(), roundState.getGameSettings().getTotalTime()); nextPlayer(); @@ -487,10 +501,12 @@ public class RoundControl { stonePoints = playerHand.isInitialMeldPossible(roundState .getGameSettings()) ? 200 : 100; } else { - stonePoints = playerHand.getStonePoints(roundState.getGameSettings()); + stonePoints = playerHand.getStonePoints(roundState + .getGameSettings()); } - bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize()); + bestScore = updateBestScore(bestScore, -stonePoints, + playerHand.getSize()); points.add(-stonePoints); pointSum += stonePoints; @@ -514,11 +530,11 @@ public class RoundControl { * (everybody still has stones on hand) * * @param bestScore - * of previous rounds + * of previous rounds * @param stonePoints - * sum of points still left on hands + * sum of points still left on hands * @param size - * number of players in game (= size of score list in columns) + * number of players in game (= size of score list in columns) * @return Pair of maximum points and hand size */ private static Pair updateBestScore( @@ -542,8 +558,8 @@ public class RoundControl { } /** - * Redeal stones and restart round if a player was allowed to redeal and chose - * to do so + * Redeal stones and restart round if a player was allowed to redeal and + * chose to do so */ private void redeal() { turnControl = null; diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java index ab4d6ae..62f9dfb 100644 --- a/src/jrummikub/control/turn/ITurnControl.java +++ b/src/jrummikub/control/turn/ITurnControl.java @@ -19,12 +19,12 @@ public interface ITurnControl { * Start the turn * * @param info - * the current turn state + * the current turn state * * @param settings - * the game settings + * the game settings * @param view - * view for user interaction. + * view for user interaction. */ public void setup(TurnInfo info, GameSettings settings, IView view); @@ -60,7 +60,8 @@ public interface ITurnControl { public IEvent1 getTableUpdateEvent(); /** - * The TurnInfo class encapsulates all information concerning the current turn + * The TurnInfo class encapsulates all information concerning the current + * turn */ public class TurnInfo { private IRoundState roundState; @@ -78,12 +79,15 @@ public interface ITurnControl { /** * Creates a new TurnInfo instance * - * @param hasLaidOut - * has the player laid out yet? + * @param roundState + * current round state * @param turnMode - * the turn mode + * the turn mode + * @param mayPause + * player is allowed to paues */ - public TurnInfo(IRoundState roundState, TurnMode turnMode, boolean mayPause) { + public TurnInfo(IRoundState roundState, TurnMode turnMode, + boolean mayPause) { this.roundState = roundState; oldTable = roundState.getTable(); @@ -97,6 +101,11 @@ public interface ITurnControl { this.mayPause = mayPause; } + /** + * Get the current round state + * + * @return the current round state + */ public IRoundState getRoundState() { return roundState; } @@ -155,6 +164,11 @@ public interface ITurnControl { return turnMode; } + /** + * Return whether pausing is allowed during this turn + * + * @return true if pause is allowed + */ public boolean isMayPause() { return mayPause; } -- cgit v1.2.3