diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/control/SettingsControl.java | 35 | ||||
-rw-r--r-- | src/jrummikub/control/network/ConnectionControl.java | 2 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkControl.java | 7 | ||||
-rw-r--r-- | src/jrummikub/control/network/NetworkSettingsControl.java | 13 | ||||
-rw-r--r-- | src/jrummikub/model/PlayerSettings.java | 2 | ||||
-rw-r--r-- | src/jrummikub/util/GameData.java | 81 | ||||
-rw-r--r-- | src/jrummikub/util/LoginData.java | 35 | ||||
-rw-r--r-- | src/jrummikub/view/IGameListPanel.java | 73 | ||||
-rw-r--r-- | src/jrummikub/view/ILoginPanel.java | 5 | ||||
-rw-r--r-- | src/jrummikub/view/ISettingsPanel.java | 46 | ||||
-rw-r--r-- | src/jrummikub/view/impl/GameListPanel.java | 1 |
11 files changed, 230 insertions, 70 deletions
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index 398ce5d..32e80fe 100644 --- a/src/jrummikub/control/SettingsControl.java +++ b/src/jrummikub/control/SettingsControl.java @@ -35,9 +35,9 @@ public class SettingsControl { * Create a new settings control * * @param view - * the view to use + * the view to use * @param settings - * initial game settings + * initial game settings */ public SettingsControl(IView view, GameSettings settings) { this.view = view; @@ -71,8 +71,8 @@ public class SettingsControl { } /** - * the start game event is emitted when the user wants to start a game and the - * settings made are valid + * the start game event is emitted when the user wants to start a game and + * the settings made are valid * * @return the event */ @@ -89,7 +89,8 @@ public class SettingsControl { private void addOptionListeners1() { connections.add(view.getSettingsPanel() - .getChangeInitialMeldThresholdEvent().add(new IListener1<Integer>() { + .getChangeInitialMeldThresholdEvent() + .add(new IListener1<Integer>() { @Override public void handle(Integer value) { settings.setInitialMeldThreshold(value); @@ -114,7 +115,8 @@ public class SettingsControl { update(); } })); - connections.add(view.getSettingsPanel().getChangeNumberOfStonesDealtEvent() + connections.add(view.getSettingsPanel() + .getChangeNumberOfStonesDealtEvent() .add(new IListener1<Integer>() { @Override public void handle(Integer value) { @@ -303,8 +305,9 @@ public class SettingsControl { view.getSettingsPanel().enableRemovePlayerButtons( Collections.nCopies(settings.getPlayerList().size(), enableRemoveButtons)); - view.getSettingsPanel().enableAddPlayerButton( - settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); + view.getSettingsPanel() + .enableAddPlayerButton( + settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); checkSettings(); @@ -317,6 +320,9 @@ public class SettingsControl { } protected boolean checkSettings() { + if (!checkName()) { + return false; + } if (!checkErrors()) { return false; } @@ -329,7 +335,7 @@ public class SettingsControl { return true; } - private boolean checkErrors() { + private boolean checkName() { for (PlayerSettings player : settings.getPlayerList()) { if (player.getName().isEmpty()) { view.getSettingsPanel().setError( @@ -350,17 +356,22 @@ public class SettingsControl { for (int j = i + 1; j < settings.getPlayerList().size(); ++j) { PlayerSettings player2 = settings.getPlayerList().get(j); if (player2.getName().equals(name) && player2.getType() == type) { - view.getSettingsPanel().setError( - ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); + view.getSettingsPanel() + .setError( + ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); view.getSettingsPanel().enableStartGameButton(false); return false; } } } + return true; + } + private boolean checkErrors() { int totalStonesDealt = settings.getNumberOfStonesDealt() * settings.getPlayerList().size(); - int totalStones = settings.getHighestValue() * settings.getStoneSetNumber() + int totalStones = settings.getHighestValue() + * settings.getStoneSetNumber() * settings.getStoneColors().size() + settings.getJokerNumber(); if (totalStones <= totalStonesDealt) { diff --git a/src/jrummikub/control/network/ConnectionControl.java b/src/jrummikub/control/network/ConnectionControl.java index fd8087a..7980c2d 100644 --- a/src/jrummikub/control/network/ConnectionControl.java +++ b/src/jrummikub/control/network/ConnectionControl.java @@ -7,10 +7,10 @@ import javax.swing.SwingUtilities; import jrummikub.model.GameSettings; import jrummikub.util.Event; import jrummikub.util.Event1; +import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.LoginData; -import jrummikub.view.IGameListPanel.GameData; import org.jivesoftware.smack.Connection; import org.jivesoftware.smack.PacketListener; diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index 929ce03..4f4dad6 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -9,12 +9,11 @@ import java.util.UUID; import jrummikub.model.GameSettings; import jrummikub.util.Connection; import jrummikub.util.Event; +import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.util.LoginData; -import jrummikub.view.IGameListPanel; -import jrummikub.view.IGameListPanel.GameData; import jrummikub.view.IView; /** @@ -45,7 +44,7 @@ public class NetworkControl { addConnectionControlListeners(loginData, view); connections.add(view.getGameListPanel().getJoinEvent() - .add(new IListener1<IGameListPanel.GameData>() { + .add(new IListener1<GameData>() { @Override public void handle(GameData value) { // TODO Auto-generated method stub @@ -107,7 +106,7 @@ public class NetworkControl { })); connections.add(connectionControl.getGameOfferEvent().add( - new IListener1<IGameListPanel.GameData>() { + new IListener1<GameData>() { @Override public void handle(GameData value) { GameData game = gameMap.get(value.getGameID()); diff --git a/src/jrummikub/control/network/NetworkSettingsControl.java b/src/jrummikub/control/network/NetworkSettingsControl.java index 61fcfa3..3c8dc42 100644 --- a/src/jrummikub/control/network/NetworkSettingsControl.java +++ b/src/jrummikub/control/network/NetworkSettingsControl.java @@ -21,12 +21,12 @@ public class NetworkSettingsControl extends SettingsControl { /** * Creates a new network settings control * - * @param connectionControl - * for gameOffers + * @param nickname + * to be set as player name * @param view - * for events and handlers + * for events and handlers * @param settings - * for playerNumber, color... + * for playerNumber, color... */ public NetworkSettingsControl(String nickname, IView view, GameSettings settings) { @@ -45,8 +45,9 @@ public class NetworkSettingsControl extends SettingsControl { @Override protected void update() { - view.getSettingsPanel().enableAddPlayerButton( - settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); + view.getSettingsPanel() + .enableAddPlayerButton( + settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); checkSettings(); diff --git a/src/jrummikub/model/PlayerSettings.java b/src/jrummikub/model/PlayerSettings.java index b08e7e1..5e9d05a 100644 --- a/src/jrummikub/model/PlayerSettings.java +++ b/src/jrummikub/model/PlayerSettings.java @@ -3,8 +3,6 @@ package jrummikub.model; import java.awt.Color; import java.io.Serializable; -import jrummikub.control.turn.TurnControlFactory; - /** * The settings of a player */ diff --git a/src/jrummikub/util/GameData.java b/src/jrummikub/util/GameData.java new file mode 100644 index 0000000..1ad651f --- /dev/null +++ b/src/jrummikub/util/GameData.java @@ -0,0 +1,81 @@ +package jrummikub.util; + +import java.util.UUID; + +import jrummikub.model.GameSettings; + +/** + * Class summarizing the game data important for unique and sensible network + * representation and use + */ +public class GameData { + private UUID gameID; + private String host; + private GameSettings gameSettings; + + /** + * Creates new game data + * + * @param gameID + * unique gameID + * @param settings + * game settings (serialized) + */ + public GameData(UUID gameID, GameSettings settings) { + this(gameID, settings, null); + } + + /** + * Creates new game data + * + * @param gameID + * unique gameID + * @param settings + * game settings (serialized) + * @param host + * name of the player offering the game + */ + public GameData(UUID gameID, GameSettings settings, String host) { + this.gameID = gameID; + this.gameSettings = settings; + this.host = host; + + } + + /** + * Sets the game settings + * + * @param settings + * game settings after adjustment + */ + public void setGameSettings(GameSettings settings) { + gameSettings = settings; + } + + /** + * Getter for game settings + * + * @return returns game settings + */ + public GameSettings getGameSettings() { + return gameSettings; + } + + /** + * Getter for host name + * + * @return host user name + */ + public String getHost() { + return host; + } + + /** + * Getter for gameID + * + * @return gameID + */ + public UUID getGameID() { + return gameID; + } +}
\ No newline at end of file diff --git a/src/jrummikub/util/LoginData.java b/src/jrummikub/util/LoginData.java index fb295c1..50ae468 100644 --- a/src/jrummikub/util/LoginData.java +++ b/src/jrummikub/util/LoginData.java @@ -1,11 +1,26 @@ package jrummikub.util; +/** + * Data needed for the login in one data type (name, server, password, channel) + */ public class LoginData { private String userName; private String serverName; private String password; private String channelName; + /** + * Creates a new set of login data + * + * @param userName + * user name in channel, player name in game + * @param serverName + * server of the user account specified in user name + * @param password + * for account with user name on server + * @param channelName + * channel in which games can be offered and played + */ public LoginData(String userName, String serverName, String password, String channelName) { this.userName = userName; @@ -14,18 +29,38 @@ public class LoginData { this.channelName = channelName; } + /** + * Getter for user name + * + * @return user name + */ public String getUserName() { return userName; } + /** + * Getter for server name + * + * @return server name + */ public String getServerName() { return serverName; } + /** + * Getter for password + * + * @return password + */ public String getPassword() { return password; } + /** + * Getter for channel name + * + * @return channel name + */ public String getChannelName() { return channelName; } diff --git a/src/jrummikub/view/IGameListPanel.java b/src/jrummikub/view/IGameListPanel.java index cb77cdc..51d6616 100644 --- a/src/jrummikub/view/IGameListPanel.java +++ b/src/jrummikub/view/IGameListPanel.java @@ -1,54 +1,55 @@ package jrummikub.view; -import java.util.UUID; - -import jrummikub.model.GameSettings; +import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; +/** + * Panel showing all offered games in the chosen channel + */ public interface IGameListPanel { - public static class GameData { - private UUID gameID; - private String host; - private GameSettings gameSettings; - - public GameData(UUID gameID, GameSettings settings) { - this(gameID, settings, null); - } - - public GameData(UUID gameID, GameSettings settings, String host) { - this.gameID = gameID; - this.gameSettings = settings; - this.host = host; - - } - - public void setGameSettings(GameSettings settings) { - gameSettings = settings; - } - - public GameSettings getGameSettings() { - return gameSettings; - } - - public String getHost() { - return host; - } - - public UUID getGameID() { - return gameID; - } - } - + /** + * Emitted when a new game is offered + * + * @return the event + */ public IEvent getOpenNewGameEvent(); + /** + * Emitted when the network game is canceled + * + * @return the event + */ public IEvent getCancelEvent(); + /** + * Emitted when the user chose to join an existing, open game + * + * @return the event + */ public IEvent1<GameData> getJoinEvent(); + /** + * Emitted when an open game is removed by the host + * + * @param game + * game data of the open game + */ public void removeGame(GameData game); + /** + * Adds a game to the list of open games + * + * @param game + * game data of the new game + */ public void addGame(GameData game); + /** + * Sets the channel name + * + * @param name + * channel name + */ public void setChannelName(String name); } diff --git a/src/jrummikub/view/ILoginPanel.java b/src/jrummikub/view/ILoginPanel.java index 688d7e3..34978aa 100644 --- a/src/jrummikub/view/ILoginPanel.java +++ b/src/jrummikub/view/ILoginPanel.java @@ -17,6 +17,11 @@ public interface ILoginPanel { */ public IEvent1<LoginData> getLoginEvent(); + /** + * Emitted when the user cancels the login process + * + * @return the event + */ public IEvent getCancelEvent(); }
\ No newline at end of file diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index f1737a9..3e56519 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -36,11 +36,17 @@ public interface ISettingsPanel { new Color(1.0f, 1.0f, 1.0f), // white }; + /** + * enables the start of a network game at a given point in game + * + * @param enable + * starting a network game + */ public void enableNetworkMode(boolean enable); /** - * The add player event is emitted when the user wants to add a player to the - * player list + * The add player event is emitted when the user wants to add a player to + * the player list * * @return the event */ @@ -87,8 +93,8 @@ public interface ISettingsPanel { public IEvent1<Integer> getChangeInitialMeldThresholdEvent(); /** - * The change StoneSet number event is emitted when the user wants to use more - * or less than 2 StoneSets per color + * The change StoneSet number event is emitted when the user wants to use + * more or less than 2 StoneSets per color * * @return number of SoneSets */ @@ -129,7 +135,7 @@ public interface ISettingsPanel { * Sets an error to display * * @param error - * the kind of error + * the kind of error */ public void setError(SettingsError error); @@ -137,7 +143,7 @@ public interface ISettingsPanel { * Enables or disables the start game button * * @param enable - * specifies if the button is to be enabled or disabled + * specifies if the button is to be enabled or disabled */ public void enableStartGameButton(boolean enable); @@ -145,7 +151,7 @@ public interface ISettingsPanel { * Enables or disables the add player button * * @param enable - * specifies if the button is to be enabled or disabled + * specifies if the button is to be enabled or disabled */ public void enableAddPlayerButton(boolean enable); @@ -153,7 +159,7 @@ public interface ISettingsPanel { * Enables or disables the remove player buttons * * @param enable - * specifies if the buttons are to be enabled or disabled + * specifies if the buttons are to be enabled or disabled */ public void enableRemovePlayerButtons(List<Boolean> enable); @@ -162,7 +168,7 @@ public interface ISettingsPanel { * Sets the game settings to display * * @param gameSettings - * the settings + * the settings */ public void setGameSettings(GameSettings gameSettings); @@ -201,12 +207,34 @@ public interface ISettingsPanel { */ public IEvent getSetVariantChildrenEvent(); + /** + * Emitted when the user wants to go back to the panel before + * + * @return the event + */ public IEvent getBackEvent(); + /** + * Sets the types of players allowed at the given point in game + * + * @param choices + * list of types for each player + */ public void setPlayerTypeChoices(List<List<Type>> choices); + /** + * Sets the names of players editable if allowed at the given point in game + * + * @param editable + * states if the players name is editable for each player + */ public void setPlayerNamesEditable(List<Boolean> editable); + /** + * Emitted when a new game is started and looking for players + * + * @return the event + */ public IEvent getOfferGameEvent(); /** diff --git a/src/jrummikub/view/impl/GameListPanel.java b/src/jrummikub/view/impl/GameListPanel.java index 28c7634..d22dc02 100644 --- a/src/jrummikub/view/impl/GameListPanel.java +++ b/src/jrummikub/view/impl/GameListPanel.java @@ -23,6 +23,7 @@ import javax.swing.border.LineBorder; import jrummikub.util.Event; import jrummikub.util.Event1; +import jrummikub.util.GameData; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.view.IGameListPanel; |