From bc835d499f2fe3c8b9c5b6bc9cfca9d9666854e9 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Sat, 18 Jun 2011 15:01:21 +0200 Subject: Fix many comments, fix tests, fix complexity git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@462 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 18 ++++--- .../control/network/ConnectionControl.java | 5 ++ src/jrummikub/control/network/GameJoinControl.java | 16 ++++++ .../control/network/GameOfferControl.java | 17 +++++++ src/jrummikub/control/network/NetworkControl.java | 58 ++++++++++++---------- 5 files changed, 79 insertions(+), 35 deletions(-) (limited to 'src/jrummikub/control') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index f060420..fb4ab0c 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -228,10 +228,12 @@ public class RoundControl { } else { List markedStones = new ArrayList(); for (Pair set : clonedTable) { - if (!set.getFirst().isValid(roundState.getGameSettings())) { - for (Stone stone : set.getFirst()) { - markedStones.add(stone); - } + if (set.getFirst().isValid(roundState.getGameSettings())) { + continue; + } + for (Stone stone : set.getFirst()) { + markedStones.add(stone); + } } view.setStoneCollectionHidden(true); @@ -401,8 +403,8 @@ public class RoundControl { .getGameSettings()); } - bestScore = updateBestScore(bestScore, -stonePoints, - playerHand.getSize()); + bestScore = updateBestScore(bestScore, -stonePoints, playerHand + .getSize()); points.add(-stonePoints); pointSum += stonePoints; @@ -424,8 +426,8 @@ public class RoundControl { private static Pair updateBestScore( Pair bestScore, int stonePoints, int size) { if (bestScore.getFirst() == stonePoints) { - return new Pair(stonePoints, Math.min( - bestScore.getSecond(), size)); + return new Pair(stonePoints, Math.min(bestScore + .getSecond(), size)); } else if (bestScore.getFirst() < stonePoints) { return new Pair(stonePoints, size); } diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index ca8537d..28684b2 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -299,6 +299,11 @@ class ConnectionControl implements IConnectionControl { String messageType = extension.getValue("messageType"); + handleMessageTypes(extension, sender, messageType); + } + + private void handleMessageTypes(DefaultPacketExtension extension, + String sender, String messageType) { if (messageType.equals("game_offer")) { UUID uuid = UUID.fromString(extension.getValue("uuid")); GameSettings settings = (GameSettings) Base64 diff --git a/src/jrummikub/control/network/GameJoinControl.java b/src/jrummikub/control/network/GameJoinControl.java index 4adc61d..489199e 100644 --- a/src/jrummikub/control/network/GameJoinControl.java +++ b/src/jrummikub/control/network/GameJoinControl.java @@ -10,8 +10,21 @@ import jrummikub.util.IListener1; import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.IView; +/** + * Control for joining a network game + */ public class GameJoinControl extends AbstractGameBeginControl { + /** + * Creates new game join control + * + * @param connectionControl + * the current connection control for events and messages + * @param gameData + * the game data for settings, game id + * @param view + * the view + */ public GameJoinControl(final IConnectionControl connectionControl, final GameData gameData, final IView view) { super(connectionControl, view, gameData, SettingsMode.NETWORK_JOIN); @@ -54,6 +67,9 @@ public class GameJoinControl extends AbstractGameBeginControl { } } + /** + * Starts the join control and sets the settings panel in game join mode + */ public void startGameJoin() { view.showSettingsPanel(true); } diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java index af060fd..0c94c1f 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -11,8 +11,21 @@ import jrummikub.util.IListener1; import jrummikub.view.ISettingsPanel.SettingsMode; import jrummikub.view.IView; +/** + * Control for network game host + */ public class GameOfferControl extends AbstractGameBeginControl { + /** + * Creates new game offer control + * + * @param connectionControl + * for events (listening and handling) + * @param settings + * the game settings for player list, colors, names + * @param view + * the view + */ public GameOfferControl(final IConnectionControl connectionControl, final GameSettings settings, final IView view) { super(connectionControl, view, @@ -57,6 +70,10 @@ public class GameOfferControl extends AbstractGameBeginControl { })); } + /** + * sends the game offer and starts the settings panel for host using network + * offer type + */ public void startGameOffer() { connectionControl.offerGame(gameData); diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index 95f48a4..a8faac5 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -44,26 +44,27 @@ public class NetworkControl { this.view = view; connectionControl = new ConnectionControl(loginData); + addConnectionSetupListeners(loginData, view); addConnectionControlListeners(loginData, view); - connections.add(view.getGameListPanel().getJoinEvent() - .add(new IListener1() { + connections.add(view.getGameListPanel().getJoinEvent().add( + new IListener1() { @Override public void handle(GameData gameData) { join(gameData); } })); - connections.add(view.getGameListPanel().getOpenNewGameEvent() - .add(new IListener() { + connections.add(view.getGameListPanel().getOpenNewGameEvent().add( + new IListener() { @Override public void handle() { createSettingsControl(); } })); - connections.add(view.getGameListPanel().getCancelEvent() - .add(new IListener() { + connections.add(view.getGameListPanel().getCancelEvent().add( + new IListener() { @Override public void handle() { abort(); @@ -87,25 +88,6 @@ public class NetworkControl { */ public void addConnectionControlListeners(final LoginData loginData, final IView view) { - connections.add(connectionControl.getConnectedEvent().add( - new IListener() { - @Override - public void handle() { - view.getGameListPanel().setChannelName( - loginData.getChannelName()); - view.showGameListPanel(true); - } - })); - - connections.add(connectionControl.getConnectionFailedEvent().add( - new IListener() { - @Override - public void handle() { - // TODO Auto-generated method stub - - } - })); - connections.add(connectionControl.getGameOfferEvent().add( new IListener1() { @Override @@ -149,6 +131,28 @@ public class NetworkControl { })); } + private void addConnectionSetupListeners(final LoginData loginData, + final IView view) { + connections.add(connectionControl.getConnectedEvent().add( + new IListener() { + @Override + public void handle() { + view.getGameListPanel().setChannelName( + loginData.getChannelName()); + view.showGameListPanel(true); + } + })); + + connections.add(connectionControl.getConnectionFailedEvent().add( + new IListener() { + @Override + public void handle() { + // TODO Auto-generated method stub + + } + })); + } + private void updateGameList() { List gameList = new ArrayList(); @@ -220,8 +224,8 @@ public class NetworkControl { } view.showGameListPanel(false); - settingsControl = new NetworkSettingsControl( - connectionControl.getNickname(), view, new GameSettings()); + settingsControl = new NetworkSettingsControl(connectionControl + .getNickname(), view, new GameSettings()); settingsControl.getOfferGameEvent().add(new IListener1() { @Override public void handle(GameSettings settings) { -- cgit v1.2.3