summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/GameControl.java22
-rw-r--r--src/jrummikub/control/LoginControl.java44
-rw-r--r--src/jrummikub/control/RoundControl.java56
-rw-r--r--src/jrummikub/control/SaveControl.java17
-rw-r--r--src/jrummikub/control/SettingsControl.java44
-rw-r--r--src/jrummikub/control/TurnTimer.java4
-rw-r--r--src/jrummikub/control/network/NetworkControl.java115
-rw-r--r--src/jrummikub/control/network/NetworkSettingsControl.java24
-rw-r--r--src/jrummikub/control/turn/AbstractTurnControl.java2
9 files changed, 231 insertions, 97 deletions
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java
index e00f136..d52b4ef 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) {
@@ -100,6 +100,14 @@ public class GameControl {
startRound();
}
+ /**
+ * Continues game after loading
+ *
+ * @param gameState
+ * the saved GameState (Players, startplayer, points)
+ * @param roundState
+ * the saved RoundState (activePlayer, Table, heap etc)
+ */
public void continueGame(GameState gameState, IRoundState roundState) {
this.gameState = gameState;
if (roundState == null) {
@@ -110,6 +118,11 @@ public class GameControl {
}
}
+ /**
+ * Clean abortion of a running game when another one is loaded or when a new
+ * one is started
+ *
+ */
public void abortGame() {
removeListeners();
if (roundControl != null) {
@@ -174,7 +187,8 @@ public class GameControl {
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);
}
diff --git a/src/jrummikub/control/LoginControl.java b/src/jrummikub/control/LoginControl.java
index 2e6b853..9355220 100644
--- a/src/jrummikub/control/LoginControl.java
+++ b/src/jrummikub/control/LoginControl.java
@@ -13,12 +13,22 @@ import jrummikub.util.IListener1;
import jrummikub.util.LoginData;
import jrummikub.view.IView;
+/**
+ * Control checking and processing login data for network game
+ *
+ */
public class LoginControl {
private IView view;
private Event1<LoginData> loginEvent = new Event1<LoginData>();
private Event cancelEvent = new Event();
private List<Connection> connections = new ArrayList<Connection>();
+ /**
+ * Constructor for login Control
+ *
+ * @param view
+ * for events which need handling
+ */
public LoginControl(final IView view) {
this.view = view;
connections.add(view.getLoginPanel().getLoginEvent()
@@ -30,27 +40,47 @@ 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
+ *
+ */
public void startLogin() {
view.showLoginPanel(true);
}
+ /**
+ * Getter for loginEvent
+ *
+ * @return loginEvent
+ */
public IEvent1<LoginData> getLoginEvent() {
return loginEvent;
}
+ /**
+ * Getter for cancelEvent
+ *
+ * @return cancelEvent
+ */
public IEvent getCancelEvent() {
return cancelEvent;
}
+ /**
+ * Control abortion once all login data have been processed or login was
+ * canceled
+ *
+ */
public void abort() {
view.showLoginPanel(false);
for (Connection c : connections) {
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 5371b0c..281b367 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -47,9 +47,9 @@ public class RoundControl {
* Create a new RoundControl using the given gameState and view
*
* @param roundState
- * initial round state
+ * initial round state
* @param view
- * view used for user interaction
+ * view used for user interaction
*/
public RoundControl(IRoundState roundState, IView view) {
this.roundState = roundState;
@@ -73,6 +73,9 @@ public class RoundControl {
continueRound();
}
+ /**
+ * Continue a saved round after loading
+ */
public void continueRound() {
connections.add(view.getStartTurnEvent().add(new IListener() {
@Override
@@ -84,6 +87,9 @@ public class RoundControl {
prepareTurn();
}
+ /**
+ * Abort round if a new one is started or a saved one is loaded
+ */
public void abortRound() {
removeListeners();
if (turnControl != null) {
@@ -102,11 +108,12 @@ public class RoundControl {
: BottomPanelType.COMPUTER_HAND_PANEL);
view.getTablePanel().setStoneSets(clonedTable.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());
if (!isHuman)
startTurn();
@@ -131,11 +138,11 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(turnMode);
}
turnControl = TurnControlFactory.getFactory(
- roundState.getActivePlayer().getPlayerSettings().getTurnControlType())
- .create();
+ roundState.getActivePlayer().getPlayerSettings()
+ .getTurnControlType()).create();
turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
- roundState.getActivePlayer().getLaidOut(), turnMode), roundState
- .getGameSettings(), view);
+ roundState.getActivePlayer().getLaidOut(), turnMode),
+ roundState.getGameSettings(), view);
turnControl.getEndOfTurnEvent().add(new IListener() {
@Override
public void handle() {
@@ -155,8 +162,10 @@ public class RoundControl {
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));
}
}
}
@@ -167,11 +176,13 @@ public class RoundControl {
int totalValue = 0;
for (StoneSet set : newSets) {
- totalValue += set.classify(roundState.getGameSettings()).getSecond();
+ totalValue += set.classify(roundState.getGameSettings())
+ .getSecond();
}
return totalValue == 0
- || totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
+ || totalValue >= roundState.getGameSettings()
+ .getInitialMeldThreshold();
}
private void endOfTurn() {
@@ -211,7 +222,8 @@ public class RoundControl {
}
if (!roundState.getActivePlayer().getLaidOut()) {
// Player touched forbidden stones
- if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) {
+ if (!tableSetDifference(clonedTable, roundState.getTable())
+ .isEmpty()) {
rejectMove();
return;
}
@@ -220,7 +232,8 @@ public class RoundControl {
return;
}
}
- Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
+ Set<Stone> tableDiff = tableDifference(roundState.getTable(),
+ clonedTable);
roundState.setTable(clonedTable);
@@ -236,7 +249,8 @@ public class RoundControl {
}
private void rejectMove() {
- Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
+ Set<Stone> tableDiff = tableDifference(roundState.getTable(),
+ clonedTable);
// deal penalty, reset
roundState.getGameHeap().putBack(tableDiff);
dealPenalty(tableDiff.size());
@@ -330,10 +344,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;
diff --git a/src/jrummikub/control/SaveControl.java b/src/jrummikub/control/SaveControl.java
index 1412199..bebe6c5 100644
--- a/src/jrummikub/control/SaveControl.java
+++ b/src/jrummikub/control/SaveControl.java
@@ -27,7 +27,7 @@ public class SaveControl {
* Creates a new SaveControl
*
* @param view
- * the view to use
+ * the view to use
*/
public SaveControl(IView view) {
view.getSaveEvent().add(new IListener1<File>() {
@@ -45,6 +45,11 @@ public class SaveControl {
});
}
+ /**
+ * Getter for loadEvent
+ *
+ * @return loadEvent
+ */
public IEvent3<GameSettings, GameState, IRoundState> getLoadEvent() {
return loadEvent;
}
@@ -53,7 +58,7 @@ public class SaveControl {
* Sets the current game settings
*
* @param gameSettings
- * the game settings
+ * the game settings
*/
public void setGameSettings(GameSettings gameSettings) {
this.gameSettings = gameSettings;
@@ -63,7 +68,7 @@ public class SaveControl {
* Sets the current game state
*
* @param gameState
- * the game state
+ * the game state
*/
public void setGameState(GameState gameState) {
this.gameState = gameState;
@@ -73,7 +78,7 @@ public class SaveControl {
* Sets the current round state
*
* @param roundState
- * the round state
+ * the round state
*/
public void setRoundState(IRoundState roundState) {
this.roundState = roundState;
@@ -110,8 +115,8 @@ public class SaveControl {
return;
}
try {
- ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(
- file));
+ ObjectOutputStream stream = new ObjectOutputStream(
+ new FileOutputStream(file));
stream.writeObject(gameSettings);
stream.writeObject(gameState);
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
index 4ad30ce..17d37a9 100644
--- a/src/jrummikub/control/SettingsControl.java
+++ b/src/jrummikub/control/SettingsControl.java
@@ -34,9 +34,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;
@@ -44,8 +44,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
*/
@@ -78,7 +78,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);
@@ -103,7 +104,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) {
@@ -126,7 +128,7 @@ public class SettingsControl {
.add(new IListener1<Integer>() {
@Override
public void handle(Integer value) {
- settings.setTime(value);
+ settings.setTotalTime(value);
update();
}
}));
@@ -147,6 +149,13 @@ public class SettingsControl {
update();
}
}));
+ addVariantListeners();
+ }
+
+ /**
+ * Add event listeners for variants, e.g. standard or children
+ */
+ public void addVariantListeners() {
connections.add(view.getSettingsPanel().getSetVariantDefaultEvent()
.add(new IListener() {
@Override
@@ -162,7 +171,7 @@ public class SettingsControl {
settings.reset();
settings.setHighestValue(10);
settings.setJokerNumber(6);
- settings.setTime(120);
+ settings.setTotalTime(120);
settings.setInitialMeldThreshold(20);
update();
}
@@ -239,7 +248,8 @@ public class SettingsControl {
break;
}
- settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color));
+ settings.getPlayerList().add(
+ new PlayerSettings("Spieler " + num, color));
update();
}
@@ -280,8 +290,9 @@ public class SettingsControl {
protected void update() {
view.getSettingsPanel().enableRemovePlayerButtons(
settings.getPlayerList().size() > 2);
- view.getSettingsPanel().enableAddPlayerButton(
- settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
+ view.getSettingsPanel()
+ .enableAddPlayerButton(
+ settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
checkSettings();
@@ -302,8 +313,9 @@ public class SettingsControl {
for (int j = i + 1; j < settings.getPlayerList().size(); ++j) {
if (settings.getPlayerList().get(j).getName().equals(name)) {
- view.getSettingsPanel().setError(
- ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR);
+ view.getSettingsPanel()
+ .setError(
+ ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR);
view.getSettingsPanel().enableStartGameButton(false);
return false;
}
@@ -312,7 +324,8 @@ public class SettingsControl {
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) {
@@ -368,6 +381,9 @@ public class SettingsControl {
startGameEvent.emit(settings);
}
+ /**
+ * Abort settings control once settings are set
+ */
public void abort() {
view.showSettingsPanel(false);
for (Connection c : connections) {
diff --git a/src/jrummikub/control/TurnTimer.java b/src/jrummikub/control/TurnTimer.java
index e64bc57..ad55d9a 100644
--- a/src/jrummikub/control/TurnTimer.java
+++ b/src/jrummikub/control/TurnTimer.java
@@ -23,7 +23,9 @@ public class TurnTimer implements ActionListener, ITurnTimer {
* Create a new timer using a given view to display the current time left
*
* @param view
- * view to display
+ * view to display
+ * @param totalTime
+ * total time for turn
*/
public TurnTimer(IView view, int totalTime) {
this.view = view;
diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java
index ed2c8e6..8a1c8e4 100644
--- a/src/jrummikub/control/network/NetworkControl.java
+++ b/src/jrummikub/control/network/NetworkControl.java
@@ -17,6 +17,9 @@ import jrummikub.view.IGameListPanel;
import jrummikub.view.IGameListPanel.GameData;
import jrummikub.view.IView;
+/**
+ * Class dealing with network connection, offering and choice of network games
+ */
public class NetworkControl {
private ConnectionControl connectionControl;
private IView view;
@@ -27,17 +30,72 @@ public class NetworkControl {
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>();
+ /**
+ * Creates a new network control
+ *
+ * @param loginData
+ * user's login data
+ * @param view
+ * for events and handlers
+ */
public NetworkControl(final LoginData loginData, final IView view) {
this.view = view;
connectionControl = new ConnectionControl(loginData);
- connections.add(connectionControl.getConnectedEvent().add(new IListener() {
- @Override
- public void handle() {
- view.getGameListPanel().setChannelName(loginData.getChannelName());
- view.showGameListPanel(true);
- }
- }));
+ addConnectionControlListeners(loginData, view);
+
+ connections.add(view.getGameListPanel().getJoinEvent()
+ .add(new IListener1<IGameListPanel.GameData>() {
+ @Override
+ public void handle(GameData value) {
+ // TODO Auto-generated method stub
+
+ }
+ }));
+
+ connections.add(view.getGameListPanel().getOpenNewGameEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ if (settingsControl == null) {
+ view.showGameListPanel(false);
+
+ settingsControl = new NetworkSettingsControl(
+ connectionControl, view, new GameSettings());
+ settingsControl.startSettings();
+ }
+ }
+ }));
+
+ connections.add(view.getGameListPanel().getCancelEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ abort();
+ stopNetworkEvent.emit();
+ }
+ }));
+ }
+
+ /**
+ * Adds the listeners for connection control events
+ *
+ * @param loginData
+ * player's login data
+ * @param view
+ * view for events
+ */
+ 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() {
@@ -76,44 +134,18 @@ public class NetworkControl {
}
}
}));
-
- connections.add(view.getGameListPanel().getJoinEvent()
- .add(new IListener1<IGameListPanel.GameData>() {
- @Override
- public void handle(GameData value) {
- // TODO Auto-generated method stub
-
- }
- }));
-
- connections.add(view.getGameListPanel().getOpenNewGameEvent()
- .add(new IListener() {
- @Override
- public void handle() {
- if (settingsControl == null) {
- view.showGameListPanel(false);
-
- settingsControl = new NetworkSettingsControl(connectionControl,
- view, new GameSettings());
- settingsControl.startSettings();
- }
- }
- }));
-
- connections.add(view.getGameListPanel().getCancelEvent()
- .add(new IListener() {
- @Override
- public void handle() {
- abort();
- stopNetworkEvent.emit();
- }
- }));
}
+ /**
+ * Starts a new network connection with the sepcified data
+ */
public void startNetwork() {
connectionControl.connect();
}
+ /**
+ * Ends the network connection if canceled
+ */
public void abort() {
for (Connection c : connections) {
c.remove();
@@ -122,6 +154,11 @@ public class NetworkControl {
view.showGameListPanel(false);
}
+ /**
+ * Getter for stopNetworkEvent
+ *
+ * @return stopNetworkEvent
+ */
public IEvent getStopNetworkEvent() {
return stopNetworkEvent;
}
diff --git a/src/jrummikub/control/network/NetworkSettingsControl.java b/src/jrummikub/control/network/NetworkSettingsControl.java
index ff62d14..0c06df4 100644
--- a/src/jrummikub/control/network/NetworkSettingsControl.java
+++ b/src/jrummikub/control/network/NetworkSettingsControl.java
@@ -7,26 +7,40 @@ import jrummikub.model.GameSettings;
import jrummikub.view.IGameListPanel.GameData;
import jrummikub.view.IView;
+/**
+ * Settings for network games, entered by host
+ */
public class NetworkSettingsControl extends SettingsControl {
private GameData gameData = new GameData(UUID.randomUUID(), settings);
private ConnectionControl connectionControl;
-
- public NetworkSettingsControl(ConnectionControl connectionControl, IView view, GameSettings settings) {
+
+ /**
+ * Creates a new network settings control
+ *
+ * @param connectionControl
+ * for gameOffers
+ * @param view
+ * for events and handlers
+ * @param settings
+ * for playerNumber, color...
+ */
+ public NetworkSettingsControl(ConnectionControl connectionControl,
+ IView view, GameSettings settings) {
super(view, settings);
this.connectionControl = connectionControl;
}
-
+
@Override
public void startSettings() {
super.startSettings();
}
-
+
@Override
protected void update() {
super.update();
connectionControl.offerGame(gameData);
}
-
+
@Override
public void abort() {
super.abort();
diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java
index 4838a08..e5a7067 100644
--- a/src/jrummikub/control/turn/AbstractTurnControl.java
+++ b/src/jrummikub/control/turn/AbstractTurnControl.java
@@ -52,7 +52,7 @@ public abstract class AbstractTurnControl implements ITurnControl {
this.settings = settings;
this.view = view;
if (timer == null) {
- timer = new TurnTimer(view, settings.getTime());
+ timer = new TurnTimer(view, settings.getTotalTime());
}
connections.add(timer.getTimeRunOutEvent().add(new IListener() {
@Override