summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-06-13 16:29:09 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-06-13 16:29:09 +0200
commitce7d43e3654f7f33357c51e578378a7b996bd587 (patch)
treefbfa3c1941e257b3f80ad82df446170d662b9403 /src/jrummikub
parent6ac71b62e309ec04feb7ebda41dd795df678e1e4 (diff)
downloadJRummikub-ce7d43e3654f7f33357c51e578378a7b996bd587.tar
JRummikub-ce7d43e3654f7f33357c51e578378a7b996bd587.zip
Viele viele Kommentare, einige zu lange oder zu komplexe Methoden gefixt
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@417 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-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
-rw-r--r--src/jrummikub/model/GameSettings.java26
-rw-r--r--src/jrummikub/model/StoneSet.java43
-rw-r--r--src/jrummikub/util/Event3.java12
-rw-r--r--src/jrummikub/util/IEvent3.java10
-rw-r--r--src/jrummikub/util/IListener3.java12
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java2
15 files changed, 298 insertions, 135 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
diff --git a/src/jrummikub/model/GameSettings.java b/src/jrummikub/model/GameSettings.java
index f52f8cf..2a2b45d 100644
--- a/src/jrummikub/model/GameSettings.java
+++ b/src/jrummikub/model/GameSettings.java
@@ -23,7 +23,7 @@ public class GameSettings implements Serializable {
private int highestValue;
private int stoneSetNumber;
private int numberOfStonesDealt;
- private int time;
+ private int totalTime;
private boolean noLimits;
private HashSet<StoneColor> stoneColors;
@@ -34,6 +34,9 @@ public class GameSettings implements Serializable {
reset();
}
+ /**
+ * Reset the game settings to the default values
+ */
public void reset() {
initialMeldThreshold = 30;
jokerPoints = 50;
@@ -41,7 +44,7 @@ public class GameSettings implements Serializable {
highestValue = 13;
stoneSetNumber = 2;
numberOfStonesDealt = 14;
- time = 60;
+ totalTime = 60;
noLimits = false;
stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE,
ORANGE, RED));
@@ -151,12 +154,23 @@ public class GameSettings implements Serializable {
this.stoneSetNumber = stoneSets;
}
- public int getTime() {
- return time;
+ /**
+ * Getter for the time for a turn
+ *
+ * @return time for a turn
+ */
+ public int getTotalTime() {
+ return totalTime;
}
- public void setTime(int time) {
- this.time = time;
+ /**
+ * Setter for the time for a turn
+ *
+ * @param totalTime
+ * for a turn
+ */
+ public void setTotalTime(int totalTime) {
+ this.totalTime = totalTime;
}
/**
diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java
index c1d7a5d..02fd797 100644
--- a/src/jrummikub/model/StoneSet.java
+++ b/src/jrummikub/model/StoneSet.java
@@ -84,25 +84,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
}
if (nonJoker == -1) {
- if (stones.size() > settings.getHighestValue()
- && stones.size() > settings.getStoneColors().size()
- && !settings.isNoLimits()) {
- return new Pair<Type, Integer>(INVALID, 0);
- } else if (stones.size() > settings.getStoneColors().size()) {
- int value = 0;
- int stoneValue = settings.getHighestValue();
- for (int i = 0; i < stones.size(); i++) {
- value += stoneValue;
- stoneValue--;
- if (stoneValue == 0) {
- stoneValue = settings.getHighestValue();
- }
- }
- return new Pair<Type, Integer>(RUN, value);
- } else {
- return new Pair<Type, Integer>(GROUP, stones.size()
- * settings.getHighestValue());
- }
+ return classifyJokersOnly(settings, nonJoker);
}
int runScore = isValidRun(nonJoker, settings);
@@ -117,6 +99,29 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
}
}
+ private Pair<Type, Integer> classifyJokersOnly(GameSettings settings,
+ int nonJoker) {
+ if (stones.size() > settings.getHighestValue()
+ && stones.size() > settings.getStoneColors().size()
+ && !settings.isNoLimits()) {
+ return new Pair<Type, Integer>(INVALID, 0);
+ } else if (stones.size() > settings.getStoneColors().size()) {
+ int value = 0;
+ int stoneValue = settings.getHighestValue();
+ for (int i = 0; i < stones.size(); i++) {
+ value += stoneValue;
+ stoneValue--;
+ if (stoneValue == 0) {
+ stoneValue = settings.getHighestValue();
+ }
+ }
+ return new Pair<Type, Integer>(RUN, value);
+ } else {
+ return new Pair<Type, Integer>(GROUP, stones.size()
+ * settings.getHighestValue());
+ }
+ }
+
/**
* Test for rule conflict within the StoneSet, assuming we have a run
*
diff --git a/src/jrummikub/util/Event3.java b/src/jrummikub/util/Event3.java
index f500495..38cdd07 100644
--- a/src/jrummikub/util/Event3.java
+++ b/src/jrummikub/util/Event3.java
@@ -6,9 +6,11 @@ import java.util.HashSet;
* Simple single parameter event generator
*
* @param <T1>
- * type of the first event parameter
+ * type of the first event parameter
* @param <T2>
- * type of the second event parameter
+ * type of the second event parameter
+ * @param <T3>
+ * type of third event parameter
*/
public class Event3<T1, T2, T3> implements IEvent3<T1, T2, T3> {
private HashSet<IListener3<T1, T2, T3>> listeners = new HashSet<IListener3<T1, T2, T3>>();
@@ -34,9 +36,11 @@ public class Event3<T1, T2, T3> implements IEvent3<T1, T2, T3> {
* Generate a single event
*
* @param value1
- * the first event parameter
+ * the first event parameter
* @param value2
- * the second event parameter
+ * the second event parameter
+ * @param value3
+ * the third event parameter
*/
public void emit(T1 value1, T2 value2, T3 value3) {
for (IListener3<T1, T2, T3> listener : listeners) {
diff --git a/src/jrummikub/util/IEvent3.java b/src/jrummikub/util/IEvent3.java
index 47ef1cd..a78223d 100644
--- a/src/jrummikub/util/IEvent3.java
+++ b/src/jrummikub/util/IEvent3.java
@@ -4,16 +4,18 @@ package jrummikub.util;
* Interface for classes that can generate events having a two parameters
*
* @param <T1>
- * type of the first event parameter
+ * type of the first event parameter
* @param <T2>
- * type of the second event parameter
+ * type of the second event parameter
+ * @param <T3>
+ * type of third event parameter
*/
public interface IEvent3<T1, T2, T3> {
/**
* Start to publish all events to a given listener
*
* @param listener
- * target listener
+ * target listener
* @return a connection to remove the listener
*/
public Connection add(IListener3<T1, T2, T3> listener);
@@ -22,7 +24,7 @@ public interface IEvent3<T1, T2, T3> {
* Stop publishing events to a given listener
*
* @param listener
- * target listener
+ * target listener
*/
public void remove(IListener3<T1, T2, T3> listener);
}
diff --git a/src/jrummikub/util/IListener3.java b/src/jrummikub/util/IListener3.java
index a4f8474..0b6b8c9 100644
--- a/src/jrummikub/util/IListener3.java
+++ b/src/jrummikub/util/IListener3.java
@@ -5,18 +5,22 @@ package jrummikub.util;
* parameters
*
* @param <T1>
- * type of the first event parameter
+ * type of the first event parameter
* @param <T2>
- * type of the first event parameter
+ * type of the second event parameter
+ * @param <T3>
+ * type of third event parameter
*/
public interface IListener3<T1, T2, T3> {
/**
* This method is called whenever a class we're listening to emits an event
*
* @param value1
- * the first event parameter
+ * the first event parameter
* @param value2
- * the second event parameter
+ * the second event parameter
+ * @param value3
+ * the third event parameter
*/
public void handle(T1 value1, T2 value2, T3 value3);
}
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index 6b80641..271be53 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -265,7 +265,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
highestValueSpinner.setValue(gameSettings.getHighestValue());
numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt());
jokerNumberSpinner.setValue(gameSettings.getJokerNumber());
- timeSpinner.setValue(gameSettings.getTime());
+ timeSpinner.setValue(gameSettings.getTotalTime());
noLimitsBox.setSelected(gameSettings.isNoLimits());
for (StoneColor color : StoneColor.values()) {