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
This commit is contained in:
Ida Massow 2011-06-13 16:29:09 +02:00
parent 6ac71b62e3
commit ce7d43e365
15 changed files with 298 additions and 135 deletions

View file

@ -33,11 +33,11 @@ public class GameControl {
* Constructor * Constructor
* *
* @param gameSettings * @param gameSettings
* the game settings * the game settings
* @param saveControl * @param saveControl
* the save control * the save control
* @param view * @param view
* the view * the view
*/ */
public GameControl(GameSettings gameSettings, SaveControl saveControl, public GameControl(GameSettings gameSettings, SaveControl saveControl,
IView view) { IView view) {
@ -100,6 +100,14 @@ public class GameControl {
startRound(); 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) { public void continueGame(GameState gameState, IRoundState roundState) {
this.gameState = gameState; this.gameState = gameState;
if (roundState == null) { 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() { public void abortGame() {
removeListeners(); removeListeners();
if (roundControl != null) { if (roundControl != null) {
@ -174,7 +187,8 @@ public class GameControl {
view.getScorePanel().setPlayers(gameSettings.getPlayerList()); view.getScorePanel().setPlayers(gameSettings.getPlayerList());
view.getScorePanel().setScores(gameState.getScores()); view.getScorePanel().setScores(gameState.getScores());
view.getScorePanel().setAccumulatedScore(gameState.getAccumulatedScore()); view.getScorePanel().setAccumulatedScore(
gameState.getAccumulatedScore());
view.getScorePanel().update(); view.getScorePanel().update();
view.showScorePanel(true); view.showScorePanel(true);
} }

View file

@ -13,12 +13,22 @@ import jrummikub.util.IListener1;
import jrummikub.util.LoginData; import jrummikub.util.LoginData;
import jrummikub.view.IView; import jrummikub.view.IView;
/**
* Control checking and processing login data for network game
*
*/
public class LoginControl { public class LoginControl {
private IView view; private IView view;
private Event1<LoginData> loginEvent = new Event1<LoginData>(); private Event1<LoginData> loginEvent = new Event1<LoginData>();
private Event cancelEvent = new Event(); private Event cancelEvent = new Event();
private List<Connection> connections = new ArrayList<Connection>(); private List<Connection> connections = new ArrayList<Connection>();
/**
* Constructor for login Control
*
* @param view
* for events which need handling
*/
public LoginControl(final IView view) { public LoginControl(final IView view) {
this.view = view; this.view = view;
connections.add(view.getLoginPanel().getLoginEvent() connections.add(view.getLoginPanel().getLoginEvent()
@ -30,27 +40,47 @@ public class LoginControl {
} }
})); }));
connections.add(view.getLoginPanel().getCancelEvent().add(new IListener() { connections.add(view.getLoginPanel().getCancelEvent()
@Override .add(new IListener() {
public void handle() { @Override
abort(); public void handle() {
cancelEvent.emit(); abort();
} cancelEvent.emit();
})); }
}));
} }
/**
* Open Login panel
*
*/
public void startLogin() { public void startLogin() {
view.showLoginPanel(true); view.showLoginPanel(true);
} }
/**
* Getter for loginEvent
*
* @return loginEvent
*/
public IEvent1<LoginData> getLoginEvent() { public IEvent1<LoginData> getLoginEvent() {
return loginEvent; return loginEvent;
} }
/**
* Getter for cancelEvent
*
* @return cancelEvent
*/
public IEvent getCancelEvent() { public IEvent getCancelEvent() {
return cancelEvent; return cancelEvent;
} }
/**
* Control abortion once all login data have been processed or login was
* canceled
*
*/
public void abort() { public void abort() {
view.showLoginPanel(false); view.showLoginPanel(false);
for (Connection c : connections) { for (Connection c : connections) {

View file

@ -47,9 +47,9 @@ public class RoundControl {
* Create a new RoundControl using the given gameState and view * Create a new RoundControl using the given gameState and view
* *
* @param roundState * @param roundState
* initial round state * initial round state
* @param view * @param view
* view used for user interaction * view used for user interaction
*/ */
public RoundControl(IRoundState roundState, IView view) { public RoundControl(IRoundState roundState, IView view) {
this.roundState = roundState; this.roundState = roundState;
@ -73,6 +73,9 @@ public class RoundControl {
continueRound(); continueRound();
} }
/**
* Continue a saved round after loading
*/
public void continueRound() { public void continueRound() {
connections.add(view.getStartTurnEvent().add(new IListener() { connections.add(view.getStartTurnEvent().add(new IListener() {
@Override @Override
@ -84,6 +87,9 @@ public class RoundControl {
prepareTurn(); prepareTurn();
} }
/**
* Abort round if a new one is started or a saved one is loaded
*/
public void abortRound() { public void abortRound() {
removeListeners(); removeListeners();
if (turnControl != null) { if (turnControl != null) {
@ -102,11 +108,12 @@ public class RoundControl {
: BottomPanelType.COMPUTER_HAND_PANEL); : BottomPanelType.COMPUTER_HAND_PANEL);
view.getTablePanel().setStoneSets(clonedTable.clone()); view.getTablePanel().setStoneSets(clonedTable.clone());
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() view.setCurrentPlayerName(roundState.getActivePlayer()
.getName()); .getPlayerSettings().getName());
view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() view.setCurrentPlayerColor(roundState.getActivePlayer()
.getColor()); .getPlayerSettings().getColor());
view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut()); view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer()
.getLaidOut());
if (!isHuman) if (!isHuman)
startTurn(); startTurn();
@ -131,11 +138,11 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(turnMode); view.getPlayerPanel().setEndTurnMode(turnMode);
} }
turnControl = TurnControlFactory.getFactory( turnControl = TurnControlFactory.getFactory(
roundState.getActivePlayer().getPlayerSettings().getTurnControlType()) roundState.getActivePlayer().getPlayerSettings()
.create(); .getTurnControlType()).create();
turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand, turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand,
roundState.getActivePlayer().getLaidOut(), turnMode), roundState roundState.getActivePlayer().getLaidOut(), turnMode),
.getGameSettings(), view); roundState.getGameSettings(), view);
turnControl.getEndOfTurnEvent().add(new IListener() { turnControl.getEndOfTurnEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
@ -155,8 +162,10 @@ public class RoundControl {
void deal() { void deal() {
for (int i = 0; i < roundState.getPlayerCount(); i++) { for (int i = 0; i < roundState.getPlayerCount(); i++) {
IHand hand = roundState.getNthNextPlayer(i).getHand(); IHand hand = roundState.getNthNextPlayer(i).getHand();
for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) { for (int j = 0; j < roundState.getGameSettings()
hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0)); .getNumberOfStonesDealt(); j++) {
hand.drop(roundState.getGameHeap().drawStone(), new Position(0,
0));
} }
} }
} }
@ -167,11 +176,13 @@ public class RoundControl {
int totalValue = 0; int totalValue = 0;
for (StoneSet set : newSets) { for (StoneSet set : newSets) {
totalValue += set.classify(roundState.getGameSettings()).getSecond(); totalValue += set.classify(roundState.getGameSettings())
.getSecond();
} }
return totalValue == 0 return totalValue == 0
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold(); || totalValue >= roundState.getGameSettings()
.getInitialMeldThreshold();
} }
private void endOfTurn() { private void endOfTurn() {
@ -211,7 +222,8 @@ public class RoundControl {
} }
if (!roundState.getActivePlayer().getLaidOut()) { if (!roundState.getActivePlayer().getLaidOut()) {
// Player touched forbidden stones // Player touched forbidden stones
if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) { if (!tableSetDifference(clonedTable, roundState.getTable())
.isEmpty()) {
rejectMove(); rejectMove();
return; return;
} }
@ -220,7 +232,8 @@ public class RoundControl {
return; return;
} }
} }
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable); Set<Stone> tableDiff = tableDifference(roundState.getTable(),
clonedTable);
roundState.setTable(clonedTable); roundState.setTable(clonedTable);
@ -236,7 +249,8 @@ public class RoundControl {
} }
private void rejectMove() { private void rejectMove() {
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable); Set<Stone> tableDiff = tableDifference(roundState.getTable(),
clonedTable);
// deal penalty, reset // deal penalty, reset
roundState.getGameHeap().putBack(tableDiff); roundState.getGameHeap().putBack(tableDiff);
dealPenalty(tableDiff.size()); dealPenalty(tableDiff.size());
@ -330,10 +344,12 @@ public class RoundControl {
stonePoints = playerHand.isInitialMeldPossible(roundState stonePoints = playerHand.isInitialMeldPossible(roundState
.getGameSettings()) ? 200 : 100; .getGameSettings()) ? 200 : 100;
} else { } 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); points.add(-stonePoints);
pointSum += stonePoints; pointSum += stonePoints;

View file

@ -27,7 +27,7 @@ public class SaveControl {
* Creates a new SaveControl * Creates a new SaveControl
* *
* @param view * @param view
* the view to use * the view to use
*/ */
public SaveControl(IView view) { public SaveControl(IView view) {
view.getSaveEvent().add(new IListener1<File>() { view.getSaveEvent().add(new IListener1<File>() {
@ -45,6 +45,11 @@ public class SaveControl {
}); });
} }
/**
* Getter for loadEvent
*
* @return loadEvent
*/
public IEvent3<GameSettings, GameState, IRoundState> getLoadEvent() { public IEvent3<GameSettings, GameState, IRoundState> getLoadEvent() {
return loadEvent; return loadEvent;
} }
@ -53,7 +58,7 @@ public class SaveControl {
* Sets the current game settings * Sets the current game settings
* *
* @param gameSettings * @param gameSettings
* the game settings * the game settings
*/ */
public void setGameSettings(GameSettings gameSettings) { public void setGameSettings(GameSettings gameSettings) {
this.gameSettings = gameSettings; this.gameSettings = gameSettings;
@ -63,7 +68,7 @@ public class SaveControl {
* Sets the current game state * Sets the current game state
* *
* @param gameState * @param gameState
* the game state * the game state
*/ */
public void setGameState(GameState gameState) { public void setGameState(GameState gameState) {
this.gameState = gameState; this.gameState = gameState;
@ -73,7 +78,7 @@ public class SaveControl {
* Sets the current round state * Sets the current round state
* *
* @param roundState * @param roundState
* the round state * the round state
*/ */
public void setRoundState(IRoundState roundState) { public void setRoundState(IRoundState roundState) {
this.roundState = roundState; this.roundState = roundState;
@ -110,8 +115,8 @@ public class SaveControl {
return; return;
} }
try { try {
ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream( ObjectOutputStream stream = new ObjectOutputStream(
file)); new FileOutputStream(file));
stream.writeObject(gameSettings); stream.writeObject(gameSettings);
stream.writeObject(gameState); stream.writeObject(gameState);

View file

@ -34,9 +34,9 @@ public class SettingsControl {
* Create a new settings control * Create a new settings control
* *
* @param view * @param view
* the view to use * the view to use
* @param settings * @param settings
* initial game settings * initial game settings
*/ */
public SettingsControl(IView view, GameSettings settings) { public SettingsControl(IView view, GameSettings settings) {
this.view = view; 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 * the start game event is emitted when the user wants to start a game and
* settings made are valid * the settings made are valid
* *
* @return the event * @return the event
*/ */
@ -78,7 +78,8 @@ public class SettingsControl {
private void addOptionListeners1() { private void addOptionListeners1() {
connections.add(view.getSettingsPanel() connections.add(view.getSettingsPanel()
.getChangeInitialMeldThresholdEvent().add(new IListener1<Integer>() { .getChangeInitialMeldThresholdEvent()
.add(new IListener1<Integer>() {
@Override @Override
public void handle(Integer value) { public void handle(Integer value) {
settings.setInitialMeldThreshold(value); settings.setInitialMeldThreshold(value);
@ -103,7 +104,8 @@ public class SettingsControl {
update(); update();
} }
})); }));
connections.add(view.getSettingsPanel().getChangeNumberOfStonesDealtEvent() connections.add(view.getSettingsPanel()
.getChangeNumberOfStonesDealtEvent()
.add(new IListener1<Integer>() { .add(new IListener1<Integer>() {
@Override @Override
public void handle(Integer value) { public void handle(Integer value) {
@ -126,7 +128,7 @@ public class SettingsControl {
.add(new IListener1<Integer>() { .add(new IListener1<Integer>() {
@Override @Override
public void handle(Integer value) { public void handle(Integer value) {
settings.setTime(value); settings.setTotalTime(value);
update(); update();
} }
})); }));
@ -147,6 +149,13 @@ public class SettingsControl {
update(); update();
} }
})); }));
addVariantListeners();
}
/**
* Add event listeners for variants, e.g. standard or children
*/
public void addVariantListeners() {
connections.add(view.getSettingsPanel().getSetVariantDefaultEvent() connections.add(view.getSettingsPanel().getSetVariantDefaultEvent()
.add(new IListener() { .add(new IListener() {
@Override @Override
@ -162,7 +171,7 @@ public class SettingsControl {
settings.reset(); settings.reset();
settings.setHighestValue(10); settings.setHighestValue(10);
settings.setJokerNumber(6); settings.setJokerNumber(6);
settings.setTime(120); settings.setTotalTime(120);
settings.setInitialMeldThreshold(20); settings.setInitialMeldThreshold(20);
update(); update();
} }
@ -239,7 +248,8 @@ public class SettingsControl {
break; break;
} }
settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color)); settings.getPlayerList().add(
new PlayerSettings("Spieler " + num, color));
update(); update();
} }
@ -280,8 +290,9 @@ public class SettingsControl {
protected void update() { protected void update() {
view.getSettingsPanel().enableRemovePlayerButtons( view.getSettingsPanel().enableRemovePlayerButtons(
settings.getPlayerList().size() > 2); settings.getPlayerList().size() > 2);
view.getSettingsPanel().enableAddPlayerButton( view.getSettingsPanel()
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); .enableAddPlayerButton(
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
checkSettings(); checkSettings();
@ -302,8 +313,9 @@ public class SettingsControl {
for (int j = i + 1; j < settings.getPlayerList().size(); ++j) { for (int j = i + 1; j < settings.getPlayerList().size(); ++j) {
if (settings.getPlayerList().get(j).getName().equals(name)) { if (settings.getPlayerList().get(j).getName().equals(name)) {
view.getSettingsPanel().setError( view.getSettingsPanel()
ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR); .setError(
ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR);
view.getSettingsPanel().enableStartGameButton(false); view.getSettingsPanel().enableStartGameButton(false);
return false; return false;
} }
@ -312,7 +324,8 @@ public class SettingsControl {
int totalStonesDealt = settings.getNumberOfStonesDealt() int totalStonesDealt = settings.getNumberOfStonesDealt()
* settings.getPlayerList().size(); * settings.getPlayerList().size();
int totalStones = settings.getHighestValue() * settings.getStoneSetNumber() int totalStones = settings.getHighestValue()
* settings.getStoneSetNumber()
* settings.getStoneColors().size() + settings.getJokerNumber(); * settings.getStoneColors().size() + settings.getJokerNumber();
if (totalStones <= totalStonesDealt) { if (totalStones <= totalStonesDealt) {
@ -368,6 +381,9 @@ public class SettingsControl {
startGameEvent.emit(settings); startGameEvent.emit(settings);
} }
/**
* Abort settings control once settings are set
*/
public void abort() { public void abort() {
view.showSettingsPanel(false); view.showSettingsPanel(false);
for (Connection c : connections) { for (Connection c : connections) {

View file

@ -23,7 +23,9 @@ public class TurnTimer implements ActionListener, ITurnTimer {
* Create a new timer using a given view to display the current time left * Create a new timer using a given view to display the current time left
* *
* @param view * @param view
* view to display * view to display
* @param totalTime
* total time for turn
*/ */
public TurnTimer(IView view, int totalTime) { public TurnTimer(IView view, int totalTime) {
this.view = view; this.view = view;

View file

@ -17,6 +17,9 @@ import jrummikub.view.IGameListPanel;
import jrummikub.view.IGameListPanel.GameData; import jrummikub.view.IGameListPanel.GameData;
import jrummikub.view.IView; import jrummikub.view.IView;
/**
* Class dealing with network connection, offering and choice of network games
*/
public class NetworkControl { public class NetworkControl {
private ConnectionControl connectionControl; private ConnectionControl connectionControl;
private IView view; private IView view;
@ -27,17 +30,72 @@ public class NetworkControl {
private Map<UUID, GameData> gameMap = new HashMap<UUID, GameData>(); 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) { public NetworkControl(final LoginData loginData, final IView view) {
this.view = view; this.view = view;
connectionControl = new ConnectionControl(loginData); connectionControl = new ConnectionControl(loginData);
connections.add(connectionControl.getConnectedEvent().add(new IListener() { addConnectionControlListeners(loginData, view);
@Override
public void handle() { connections.add(view.getGameListPanel().getJoinEvent()
view.getGameListPanel().setChannelName(loginData.getChannelName()); .add(new IListener1<IGameListPanel.GameData>() {
view.showGameListPanel(true); @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( connections.add(connectionControl.getConnectionFailedEvent().add(
new IListener() { 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() { public void startNetwork() {
connectionControl.connect(); connectionControl.connect();
} }
/**
* Ends the network connection if canceled
*/
public void abort() { public void abort() {
for (Connection c : connections) { for (Connection c : connections) {
c.remove(); c.remove();
@ -122,6 +154,11 @@ public class NetworkControl {
view.showGameListPanel(false); view.showGameListPanel(false);
} }
/**
* Getter for stopNetworkEvent
*
* @return stopNetworkEvent
*/
public IEvent getStopNetworkEvent() { public IEvent getStopNetworkEvent() {
return stopNetworkEvent; return stopNetworkEvent;
} }

View file

@ -7,26 +7,40 @@ import jrummikub.model.GameSettings;
import jrummikub.view.IGameListPanel.GameData; import jrummikub.view.IGameListPanel.GameData;
import jrummikub.view.IView; import jrummikub.view.IView;
/**
* Settings for network games, entered by host
*/
public class NetworkSettingsControl extends SettingsControl { public class NetworkSettingsControl extends SettingsControl {
private GameData gameData = new GameData(UUID.randomUUID(), settings); private GameData gameData = new GameData(UUID.randomUUID(), settings);
private ConnectionControl connectionControl; 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); super(view, settings);
this.connectionControl = connectionControl; this.connectionControl = connectionControl;
} }
@Override @Override
public void startSettings() { public void startSettings() {
super.startSettings(); super.startSettings();
} }
@Override @Override
protected void update() { protected void update() {
super.update(); super.update();
connectionControl.offerGame(gameData); connectionControl.offerGame(gameData);
} }
@Override @Override
public void abort() { public void abort() {
super.abort(); super.abort();

View file

@ -52,7 +52,7 @@ public abstract class AbstractTurnControl implements ITurnControl {
this.settings = settings; this.settings = settings;
this.view = view; this.view = view;
if (timer == null) { if (timer == null) {
timer = new TurnTimer(view, settings.getTime()); timer = new TurnTimer(view, settings.getTotalTime());
} }
connections.add(timer.getTimeRunOutEvent().add(new IListener() { connections.add(timer.getTimeRunOutEvent().add(new IListener() {
@Override @Override

View file

@ -23,7 +23,7 @@ public class GameSettings implements Serializable {
private int highestValue; private int highestValue;
private int stoneSetNumber; private int stoneSetNumber;
private int numberOfStonesDealt; private int numberOfStonesDealt;
private int time; private int totalTime;
private boolean noLimits; private boolean noLimits;
private HashSet<StoneColor> stoneColors; private HashSet<StoneColor> stoneColors;
@ -34,6 +34,9 @@ public class GameSettings implements Serializable {
reset(); reset();
} }
/**
* Reset the game settings to the default values
*/
public void reset() { public void reset() {
initialMeldThreshold = 30; initialMeldThreshold = 30;
jokerPoints = 50; jokerPoints = 50;
@ -41,7 +44,7 @@ public class GameSettings implements Serializable {
highestValue = 13; highestValue = 13;
stoneSetNumber = 2; stoneSetNumber = 2;
numberOfStonesDealt = 14; numberOfStonesDealt = 14;
time = 60; totalTime = 60;
noLimits = false; noLimits = false;
stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE, stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE,
ORANGE, RED)); ORANGE, RED));
@ -151,12 +154,23 @@ public class GameSettings implements Serializable {
this.stoneSetNumber = stoneSets; 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;
} }
/** /**

View file

@ -84,25 +84,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
} }
if (nonJoker == -1) { if (nonJoker == -1) {
if (stones.size() > settings.getHighestValue() return classifyJokersOnly(settings, nonJoker);
&& 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());
}
} }
int runScore = isValidRun(nonJoker, settings); 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 * Test for rule conflict within the StoneSet, assuming we have a run
* *

View file

@ -6,9 +6,11 @@ import java.util.HashSet;
* Simple single parameter event generator * Simple single parameter event generator
* *
* @param <T1> * @param <T1>
* type of the first event parameter * type of the first event parameter
* @param <T2> * @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> { public class Event3<T1, T2, T3> implements IEvent3<T1, T2, T3> {
private HashSet<IListener3<T1, T2, T3>> listeners = new HashSet<IListener3<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 * Generate a single event
* *
* @param value1 * @param value1
* the first event parameter * the first event parameter
* @param value2 * @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) { public void emit(T1 value1, T2 value2, T3 value3) {
for (IListener3<T1, T2, T3> listener : listeners) { for (IListener3<T1, T2, T3> listener : listeners) {

View file

@ -4,16 +4,18 @@ package jrummikub.util;
* Interface for classes that can generate events having a two parameters * Interface for classes that can generate events having a two parameters
* *
* @param <T1> * @param <T1>
* type of the first event parameter * type of the first event parameter
* @param <T2> * @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> { public interface IEvent3<T1, T2, T3> {
/** /**
* Start to publish all events to a given listener * Start to publish all events to a given listener
* *
* @param listener * @param listener
* target listener * target listener
* @return a connection to remove the listener * @return a connection to remove the listener
*/ */
public Connection add(IListener3<T1, T2, T3> 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 * Stop publishing events to a given listener
* *
* @param listener * @param listener
* target listener * target listener
*/ */
public void remove(IListener3<T1, T2, T3> listener); public void remove(IListener3<T1, T2, T3> listener);
} }

View file

@ -5,18 +5,22 @@ package jrummikub.util;
* parameters * parameters
* *
* @param <T1> * @param <T1>
* type of the first event parameter * type of the first event parameter
* @param <T2> * @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> { public interface IListener3<T1, T2, T3> {
/** /**
* This method is called whenever a class we're listening to emits an event * This method is called whenever a class we're listening to emits an event
* *
* @param value1 * @param value1
* the first event parameter * the first event parameter
* @param value2 * @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); public void handle(T1 value1, T2 value2, T3 value3);
} }

View file

@ -265,7 +265,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
highestValueSpinner.setValue(gameSettings.getHighestValue()); highestValueSpinner.setValue(gameSettings.getHighestValue());
numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt()); numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt());
jokerNumberSpinner.setValue(gameSettings.getJokerNumber()); jokerNumberSpinner.setValue(gameSettings.getJokerNumber());
timeSpinner.setValue(gameSettings.getTime()); timeSpinner.setValue(gameSettings.getTotalTime());
noLimitsBox.setSelected(gameSettings.isNoLimits()); noLimitsBox.setSelected(gameSettings.isNoLimits());
for (StoneColor color : StoneColor.values()) { for (StoneColor color : StoneColor.values()) {