From 74d8205f30732a8afd6aa45f859188b0a3d447e5 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Mon, 20 Jun 2011 04:39:54 +0200 Subject: Kommentare, Kommentare git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@509 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 7 ++++- .../control/network/GameOfferControl.java | 36 +++++++++++++--------- src/jrummikub/control/network/NetworkControl.java | 17 +++++++--- src/jrummikub/control/turn/AIControl.java | 16 ++++++---- src/jrummikub/control/turn/ITurnControl.java | 22 ++++++++----- 5 files changed, 63 insertions(+), 35 deletions(-) (limited to 'src/jrummikub/control') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 2936627..ba0fa2a 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -1,6 +1,6 @@ package jrummikub.control; -import static jrummikub.model.PlayerSettings.Type.*; +import static jrummikub.model.PlayerSettings.Type.HUMAN; import java.util.ArrayList; import java.util.Collections; @@ -64,6 +64,11 @@ public class RoundControl { this.view = view; } + /** + * Is emitted in network when a new turn starts + * + * @return the event + */ public IEvent1 getRoundStateUpdateEvent() { return roundStateUpdateEvent; } diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java index 42e3b8b..b513170 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -36,6 +36,27 @@ public class GameOfferControl extends AbstractGameBeginControl { super(connectionControl, view, new GameData(UUID.randomUUID(), settings), SettingsMode.NETWORK_OFFER); + addConnectionControlListeners(connectionControl, settings); + + connections.add(view.getSettingsPanel().getStartGameEvent() + .add(new IListener() { + @Override + public void handle() { + List players = gameData.getGameSettings() + .getPlayerList(); + for (PlayerSettings s : players) { + if (s.getType() == Type.NETWORK) { + startGame(); + return; + } + } + } + })); + } + + private void addConnectionControlListeners( + final IConnectionControl connectionControl, + final GameSettings settings) { connections.add(connectionControl.getGameJoinEvent().add( new IListener1() { @Override @@ -71,21 +92,6 @@ public class GameOfferControl extends AbstractGameBeginControl { connectionControl.offerGame(gameData); } })); - - connections.add(view.getSettingsPanel().getStartGameEvent() - .add(new IListener() { - @Override - public void handle() { - List players = gameData.getGameSettings() - .getPlayerList(); - for (PlayerSettings s : players) { - if (s.getType() == Type.NETWORK) { - startGame(); - return; - } - } - } - })); } /** diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index 0d0fbe9..4c03923 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -57,11 +57,11 @@ public class NetworkControl { * Creates a new network control * * @param loginData - * user's login data + * user's login data * @param connectionControl - * current connection for events and messages + * current connection for events and messages * @param view - * for events and handlers + * for events and handlers */ public NetworkControl(final LoginData loginData, IConnectionControl connectionControl, SaveControl saveControl, @@ -108,7 +108,7 @@ public class NetworkControl { * Adds the listeners for connection control events * * @param view - * view for events + * view for events */ public void addConnectionControlListeners(final IView view) { connections.add(connectionControl.getGameOfferEvent().add( @@ -260,6 +260,12 @@ public class NetworkControl { return stopNetworkEvent; } + /** + * The back to login event is emitted when the player aborted the connecting + * process or when a connection error has occured and been acknowledged + * + * @return the event + */ public IEvent getBackToLoginEvent() { return backToLoginEvent; } @@ -293,7 +299,8 @@ public class NetworkControl { if (gameOfferControl != null) { return; } - gameOfferControl = new GameOfferControl(connectionControl, settings, view); + gameOfferControl = new GameOfferControl(connectionControl, settings, + view); gameOfferControl.getBackEvent().add(new IListener() { @Override public void handle() { diff --git a/src/jrummikub/control/turn/AIControl.java b/src/jrummikub/control/turn/AIControl.java index ba222ea..8bcf661 100644 --- a/src/jrummikub/control/turn/AIControl.java +++ b/src/jrummikub/control/turn/AIControl.java @@ -21,6 +21,9 @@ import jrummikub.util.Pair; */ public class AIControl extends AbstractTurnControl { private TurnLogic logic; + /** + * Does the AI control currently use an internal timer + */ public static boolean useBackgroundThread = true; long startTime; @@ -63,7 +66,7 @@ public class AIControl extends AbstractTurnControl { turnDone = true; super.cleanUp(); } - + @Override public void abortTurn() { aborted = true; @@ -160,8 +163,8 @@ public class AIControl extends AbstractTurnControl { for (StoneSet set : result) { turnInfo.getTable().drop( set, - new Position(10 * (Math.random() * 2 - 1), - 5 * (Math.random() * 2 - 1))); + new Position(10 * (Math.random() * 2 - 1), 5 * (Math + .random() * 2 - 1))); for (Stone stone : set) { turnInfo.getHand().pickUp(stone); } @@ -173,10 +176,11 @@ public class AIControl extends AbstractTurnControl { private void doNotMoveExistingSets(List result) { - outerLoop: for (Iterator> it = turnInfo.getTable() - .iterator(); it.hasNext();) { + outerLoop: for (Iterator> it = turnInfo + .getTable().iterator(); it.hasNext();) { Pair pair = it.next(); - setSearch: for (Iterator it2 = result.iterator(); it2.hasNext();) { + setSearch: for (Iterator it2 = result.iterator(); it2 + .hasNext();) { StoneSet set = it2.next(); if (set.getSize() != pair.getFirst().getSize()) { continue; diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java index 1860d69..66bd065 100644 --- a/src/jrummikub/control/turn/ITurnControl.java +++ b/src/jrummikub/control/turn/ITurnControl.java @@ -16,12 +16,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); @@ -49,10 +49,16 @@ public interface ITurnControl { */ public void abortTurn(); + /** + * Emitted in network when the table changes during player turn + * + * @return the event + */ 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 ITable table; @@ -64,13 +70,13 @@ public interface ITurnControl { * Creates a new TurnInfo instance * * @param table - * the current table + * the current table * @param hand - * the current player's hand + * the current player's hand * @param hasLaidOut - * has the player laid out yet? + * has the player laid out yet? * @param turnMode - * the turn mode + * the turn mode */ public TurnInfo(ITable table, IHand hand, boolean hasLaidOut, TurnMode turnMode) { -- cgit v1.2.3