Das reine control-package ist vollständig kommentiert

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@545 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-06-21 13:47:15 +02:00
parent fcd7af7628
commit 5e3ce21569
7 changed files with 321 additions and 48 deletions

View file

@ -49,6 +49,9 @@ public abstract class AbstractSettingsControl {
.asList(ISettingsPanel.PLAYER_COLORS))); .asList(ISettingsPanel.PLAYER_COLORS)));
} }
/**
* Add event listeners to abstract settings control
*/
protected void addListeners() { protected void addListeners() {
addPlayerSettingsListeners(); addPlayerSettingsListeners();
@ -57,6 +60,9 @@ public abstract class AbstractSettingsControl {
addVariantListeners(); addVariantListeners();
} }
/**
* Add event listeners to the player settings panel
*/
private void addPlayerSettingsListeners() { private void addPlayerSettingsListeners() {
connections.add(view.getSettingsPanel().getAddPlayerEvent() connections.add(view.getSettingsPanel().getAddPlayerEvent()
.add(new IListener() { .add(new IListener() {
@ -95,6 +101,9 @@ public abstract class AbstractSettingsControl {
})); }));
} }
/**
* Add the first half of event listeners to option panel
*/
private void addOptionListeners1() { private void addOptionListeners1() {
connections.add(view.getSettingsPanel() connections.add(view.getSettingsPanel()
.getChangeInitialMeldThresholdEvent() .getChangeInitialMeldThresholdEvent()
@ -134,6 +143,9 @@ public abstract class AbstractSettingsControl {
})); }));
} }
/**
* Add the second half of event listeners to option panel
*/
private void addOptionListeners2() { private void addOptionListeners2() {
connections.add(view.getSettingsPanel().getChangeHighestValueEvent() connections.add(view.getSettingsPanel().getChangeHighestValueEvent()
.add(new IListener1<Integer>() { .add(new IListener1<Integer>() {
@ -168,7 +180,7 @@ public abstract class AbstractSettingsControl {
update(); update();
} }
})); }));
connections.add(view.getSettingsPanel().getChangeSeeHandSizeEvent() connections.add(view.getSettingsPanel().getChangeSeeHandSizeEvent()
.add(new IListener1<Boolean>() { .add(new IListener1<Boolean>() {
@Override @Override
@ -212,6 +224,11 @@ public abstract class AbstractSettingsControl {
view.showSettingsPanel(true); view.showSettingsPanel(true);
} }
/**
* Finds the next unused player color
*
* @return an unused color
*/
protected Color findUnusedColor() { protected Color findUnusedColor() {
Color color = null; Color color = null;
colorLoop: for (Color c : ISettingsPanel.PLAYER_COLORS) { colorLoop: for (Color c : ISettingsPanel.PLAYER_COLORS) {
@ -226,6 +243,14 @@ public abstract class AbstractSettingsControl {
return color; return color;
} }
/**
* Sets a player's color
*
* @param i
* index of player
* @param color
* color to be set
*/
private void setPlayerColor(int i, Color color) { private void setPlayerColor(int i, Color color) {
PlayerSettings player = settings.getPlayerList().get(i); PlayerSettings player = settings.getPlayerList().get(i);
@ -244,16 +269,36 @@ public abstract class AbstractSettingsControl {
update(); update();
} }
/**
* Sets a player's name
*
* @param i
* index of player
* @param name
* name to be set
*/
private void setPlayerName(int i, String name) { private void setPlayerName(int i, String name) {
settings.getPlayerList().get(i).setName(name); settings.getPlayerList().get(i).setName(name);
update(); update();
} }
/**
* Removes a player from the planned game
*
* @param i
* index of player
*/
private void removePlayer(int i) { private void removePlayer(int i) {
settings.getPlayerList().remove(i); settings.getPlayerList().remove(i);
update(); update();
} }
/**
* Checks the settings for ambiguous or missing data and sets error/warning
* if necessary
*
* @return boolean check correct
*/
protected boolean checkSettings() { protected boolean checkSettings() {
if (!checkName()) { if (!checkName()) {
return false; return false;
@ -270,6 +315,11 @@ public abstract class AbstractSettingsControl {
return true; return true;
} }
/**
* Checks if unique player name is present for each player
*
* @return is player name ok
*/
private boolean checkName() { private boolean checkName() {
for (PlayerSettings player : settings.getPlayerList()) { for (PlayerSettings player : settings.getPlayerList()) {
if (player.getName().isEmpty()) { if (player.getName().isEmpty()) {
@ -302,6 +352,11 @@ public abstract class AbstractSettingsControl {
return true; return true;
} }
/**
* Check options leading to errors
*
* @return options ok
*/
private boolean checkErrors() { private boolean checkErrors() {
int totalStonesDealt = settings.getNumberOfStonesDealt() int totalStonesDealt = settings.getNumberOfStonesDealt()
* settings.getPlayerList().size(); * settings.getPlayerList().size();
@ -324,6 +379,9 @@ public abstract class AbstractSettingsControl {
return true; return true;
} }
/**
* Check all options and player settings for entries causing warnings
*/
private void checkWarnings() { private void checkWarnings() {
if (settings.getInitialMeldThreshold() >= 100) { if (settings.getInitialMeldThreshold() >= 100) {
view.getSettingsPanel().setError( view.getSettingsPanel().setError(
@ -356,10 +414,24 @@ public abstract class AbstractSettingsControl {
} }
} }
/**
* Add new player to the planned game
*/
abstract protected void addPlayer(); abstract protected void addPlayer();
/**
* Set the type of a player
*
* @param i
* index of player
* @param type
* type to be set
*/
abstract protected void setPlayerType(int i, Type type); abstract protected void setPlayerType(int i, Type type);
/**
* Show newly chosen options in view
*/
abstract protected void update(); abstract protected void update();
} }

View file

@ -118,6 +118,9 @@ public class ApplicationControl {
}); });
} }
/**
* Create a new network login control
*/
private void createLoginControl() { private void createLoginControl() {
loginControl = new LoginControl(view); loginControl = new LoginControl(view);
loginControl.getLoginEvent().add(new IListener1<LoginData>() { loginControl.getLoginEvent().add(new IListener1<LoginData>() {
@ -135,6 +138,9 @@ public class ApplicationControl {
loginControl.startLogin(); loginControl.startLogin();
} }
/**
* End all controls in case of e.g. quit event
*/
private void abortControls() { private void abortControls() {
if (settingsControl != null) { if (settingsControl != null) {
settingsControl.abort(); settingsControl.abort();
@ -191,6 +197,12 @@ public class ApplicationControl {
settingsControl.startSettings(); settingsControl.startSettings();
} }
/**
* Adds events listeners to game control events
*
* @param gameControl
* of current game
*/
private void addGameControlListeners(GameControl gameControl) { private void addGameControlListeners(GameControl gameControl) {
gameControl.getEndOfGameEvent().add(new IListener() { gameControl.getEndOfGameEvent().add(new IListener() {
@Override @Override
@ -200,6 +212,12 @@ public class ApplicationControl {
}); });
} }
/**
* Create a new network game control
*
* @param loginData
* users login data for channel
*/
private void createNetworkControl(LoginData loginData) { private void createNetworkControl(LoginData loginData) {
ConnectionControl connectionControl = new ConnectionControl(loginData); ConnectionControl connectionControl = new ConnectionControl(loginData);
networkControl = new NetworkControl(loginData, connectionControl, networkControl = new NetworkControl(loginData, connectionControl,

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) {
@ -49,8 +49,9 @@ public class GameControl {
gameState = new GameState(); gameState = new GameState();
saveControl.setGameState(gameState); saveControl.setGameState(gameState);
gameState.setFirstRoundFirstPlayer((int) (Math.random() * gameSettings gameState
.getPlayerList().size())); .setFirstRoundFirstPlayer((int) (Math.random() * gameSettings
.getPlayerList().size()));
} }
connections.add(view.getNewRoundEvent().add(new IListener() { connections.add(view.getNewRoundEvent().add(new IListener() {
@ -84,11 +85,17 @@ public class GameControl {
return endOfGameEvent; return endOfGameEvent;
} }
/**
* Ends the running game
*/
private void endGame() { private void endGame() {
removeListeners(); removeListeners();
endOfGameEvent.emit(); endOfGameEvent.emit();
} }
/**
* Removes all listeners from the connection
*/
private void removeListeners() { private void removeListeners() {
for (Connection c : connections) { for (Connection c : connections) {
c.remove(); c.remove();
@ -106,9 +113,9 @@ public class GameControl {
* Continues game after loading * Continues game after loading
* *
* @param gameState * @param gameState
* the saved GameState (Players, startplayer, points) * the saved GameState (Players, startplayer, points)
* @param roundState * @param roundState
* the saved RoundState (activePlayer, Table, heap etc) * 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;
@ -135,6 +142,9 @@ public class GameControl {
view.clearView(); view.clearView();
} }
/**
* Start a new round within the existing game
*/
protected void startRound() { protected void startRound() {
if (roundControl != null) { if (roundControl != null) {
return; return;
@ -147,22 +157,29 @@ public class GameControl {
roundControl.startRound(); roundControl.startRound();
} }
/**
* Prepare a new round by setting start player, adding listeners
*
* @param roundState
* of current round
*/
private void prepareRound(IRoundState roundState) { private void prepareRound(IRoundState roundState) {
saveControl.setRoundState(roundState); saveControl.setRoundState(roundState);
if (roundState != null) { if (roundState != null) {
roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer() roundState.setActivePlayerNumber(gameState
+ gameState.getScores().size()); .getFirstRoundFirstPlayer() + gameState.getScores().size());
} }
roundControl = createRoundControl(roundState); roundControl = createRoundControl(roundState);
roundControl.getRoundStateUpdateEvent().add(new IListener1<IRoundState>() { roundControl.getRoundStateUpdateEvent().add(
@Override new IListener1<IRoundState>() {
public void handle(IRoundState newState) { @Override
gameState = newState.getGameState(); public void handle(IRoundState newState) {
gameSettings = newState.getGameSettings(); gameState = newState.getGameState();
} gameSettings = newState.getGameSettings();
}); }
});
roundControl.getEndOfRoundEvent().add(new IListener1<Score>() { roundControl.getEndOfRoundEvent().add(new IListener1<Score>() {
@Override @Override
public void handle(Score roundScore) { public void handle(Score roundScore) {
@ -179,19 +196,40 @@ public class GameControl {
}); });
} }
/**
* Creates a new round State
*
* @return the round state
*/
protected IRoundState createRoundState() { protected IRoundState createRoundState() {
return new RoundState(gameSettings, gameState); return new RoundState(gameSettings, gameState);
} }
/**
* Creates a new round control with the specified round state
*
* @param roundState
* for new round control
* @return the round control
*/
protected RoundControl createRoundControl(IRoundState roundState) { protected RoundControl createRoundControl(IRoundState roundState) {
return new RoundControl(roundState, view); return new RoundControl(roundState, view);
} }
/**
* Restarts round after loading
*/
private void restartRound() { private void restartRound() {
roundControl = null; roundControl = null;
startRound(); startRound();
} }
/**
* Sets the score and default values for saving when round ends
*
* @param roundScore
* score for ended round
*/
private void endOfRound(Score roundScore) { private void endOfRound(Score roundScore) {
gameState.getScores().add(roundScore); gameState.getScores().add(roundScore);
saveControl.setRoundState(null); saveControl.setRoundState(null);
@ -200,17 +238,24 @@ public class GameControl {
showScorePanel(); showScorePanel();
} }
/**
* Sets score panel visible
*/
private void showScorePanel() { private void showScorePanel() {
view.showSidePanel(false); view.showSidePanel(false);
view.setBottomPanel(BottomPanelType.WIN_PANEL); view.setBottomPanel(BottomPanelType.WIN_PANEL);
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);
} }
/**
* Exits System without warnings if no game control is active
*/
private void endProgram() { private void endProgram() {
System.exit(0); System.exit(0);
} }

View file

@ -36,7 +36,6 @@ public class LoginControl {
@Override @Override
public void handle(LoginData loginData) { public void handle(LoginData loginData) {
abort(); abort();
// TODO connectPanel anzeigen
loginEvent.emit(loginData); loginEvent.emit(loginData);
} }
})); }));

View file

@ -37,10 +37,29 @@ import jrummikub.view.IView.BottomPanelType;
* Controller that manages a single round of rummikub * Controller that manages a single round of rummikub
*/ */
public class RoundControl { public class RoundControl {
/**
* Enum summarizing the different types of invalid turns to set the correct
* panel message
*/
public enum InvalidTurnType { public enum InvalidTurnType {
INVALID_SETS, INITIAL_MELD_ERROR, NOT_ENOUGH_POINTS /** There are invalid set(s) on the table */
INVALID_SETS,
/**
* The player tried to modify the table without providing the initial
* meld threshold first
*/
INITIAL_MELD_ERROR,
/**
* The player didn't provide enough points for the initial meld
* threshold
*/
NOT_ENOUGH_POINTS
} }
/**
* Table, stone sets and type of an invalid turn to allow a user to track
* his own errors
*/
public static class InvalidTurnInfo implements Serializable { public static class InvalidTurnInfo implements Serializable {
private static final long serialVersionUID = -3591000741414366776L; private static final long serialVersionUID = -3591000741414366776L;
@ -48,6 +67,16 @@ public class RoundControl {
private InvalidTurnType type; private InvalidTurnType type;
private ArrayList<StoneSet> invalidSets; private ArrayList<StoneSet> invalidSets;
/**
* Creates new InvalidTurnInfo
*
* @param table
* the table after the turn
* @param type
* the type of the invalid turn
* @param invalidSets
* the sets causing the turn to be invalid
*/
public InvalidTurnInfo(ITable table, InvalidTurnType type, public InvalidTurnInfo(ITable table, InvalidTurnType type,
Collection<StoneSet> invalidSets) { Collection<StoneSet> invalidSets) {
this.table = (ITable) table.clone(); this.table = (ITable) table.clone();
@ -55,14 +84,29 @@ public class RoundControl {
this.invalidSets = new ArrayList<StoneSet>(invalidSets); this.invalidSets = new ArrayList<StoneSet>(invalidSets);
} }
/**
* Getter for table
*
* @return the table
*/
public ITable getTable() { public ITable getTable() {
return table; return table;
} }
/**
* Getter for invalid turn type
*
* @return the type
*/
public InvalidTurnType getType() { public InvalidTurnType getType() {
return type; return type;
} }
/**
* Getter for the invalid sets
*
* @return invalid sets
*/
public List<StoneSet> getInvalidSets() { public List<StoneSet> getInvalidSets() {
return invalidSets; return invalidSets;
} }
@ -86,9 +130,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
*/ */
protected RoundControl(IRoundState roundState, IView view, boolean mayPause) { protected RoundControl(IRoundState roundState, IView view, boolean mayPause) {
this.roundState = roundState; this.roundState = roundState;
@ -160,11 +204,21 @@ public class RoundControl {
} }
} }
/**
* Sets the current round state
*
* @param state
* to be set
*/
protected void setRoundState(IRoundState state) { protected void setRoundState(IRoundState state) {
roundState = state; roundState = state;
roundStateUpdateEvent.emit(state); roundStateUpdateEvent.emit(state);
} }
/**
* Prepare a player's turn by checking the player types and setting the
* correct turn control
*/
protected void prepareTurn() { protected void prepareTurn() {
doPrepareTurn(); doPrepareTurn();
@ -178,6 +232,9 @@ public class RoundControl {
} }
} }
/**
* Prepare turn by setting the view components
*/
protected void doPrepareTurn() { protected void doPrepareTurn() {
updateSidePanel(); updateSidePanel();
@ -190,16 +247,20 @@ public class RoundControl {
} }
view.getTablePanel().setStoneSets(roundState.getTable().clone()); view.getTablePanel().setStoneSets(roundState.getTable().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());
turnControl = createTurnControl(roundState.getActivePlayer() turnControl = createTurnControl(roundState.getActivePlayer()
.getPlayerSettings().getType()); .getPlayerSettings().getType());
} }
/**
* Start a players turn with the correct turn control
*/
protected void startTurn() { protected void startTurn() {
if (turnControl == null) { if (turnControl == null) {
doPrepareTurn(); doPrepareTurn();
@ -250,6 +311,9 @@ public class RoundControl {
turnControl.startTurn(); turnControl.startTurn();
} }
/**
* Update the side panel to show correct player order and heap size
*/
private void updateSidePanel() { private void updateSidePanel() {
view.showSidePanel(true); view.showSidePanel(true);
view.getSidePanel().setGameSettings(roundState.getGameSettings()); view.getSidePanel().setGameSettings(roundState.getGameSettings());
@ -263,25 +327,49 @@ public class RoundControl {
view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize()); view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize());
} }
/** Override this */ /**
* Override this
*
* @param turnControl
* current turn control
*/
protected void addTurnControlListeners(ITurnControl turnControl) { protected void addTurnControlListeners(ITurnControl turnControl) {
} }
/**
* Creates new turn control of the specified type
*
* @param type
* of the new turn control
* @return the new turn control
*/
protected ITurnControl createTurnControl(Type type) { protected ITurnControl createTurnControl(Type type) {
return TurnControlFactory.getFactory(type).create(); return TurnControlFactory.getFactory(type).create();
} }
/**
* Deal each player the number of stones specified in the game settings
* (numberOfStonesDealt)
*/
protected void deal() { protected 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));
} }
} }
view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize()); view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize());
} }
/**
* End the players turn
*
* @param invalidTurnInfo
* info about the player's last turn
*/
protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) { protected void endOfTurn(InvalidTurnInfo invalidTurnInfo) {
boolean wasAI = turnControl instanceof AIControl; boolean wasAI = turnControl instanceof AIControl;
boolean wasHuman = turnControl instanceof HumanTurnControl; boolean wasHuman = turnControl instanceof HumanTurnControl;
@ -298,16 +386,16 @@ public class RoundControl {
view.setInvalidStoneSets(invalidTurnInfo.getInvalidSets()); view.setInvalidStoneSets(invalidTurnInfo.getInvalidSets());
switch (invalidTurnInfo.getType()) { switch (invalidTurnInfo.getType()) {
case INITIAL_MELD_ERROR: case INITIAL_MELD_ERROR:
view.setInitialMeldFirstError(); view.setInitialMeldFirstError();
break; break;
case INVALID_SETS: case INVALID_SETS:
view.setStoneCollectionHidden(true); view.setStoneCollectionHidden(true);
break; break;
case NOT_ENOUGH_POINTS: case NOT_ENOUGH_POINTS:
view.setInitialMeldError(roundState.getGameSettings() view.setInitialMeldError(roundState.getGameSettings()
.getInitialMeldThreshold()); .getInitialMeldThreshold());
break; break;
} }
if (wasAI) { if (wasAI) {
@ -330,6 +418,9 @@ public class RoundControl {
} }
} }
/**
* Set the next player as active player if the round is not finished
*/
protected void nextPlayer() { protected void nextPlayer() {
view.setSelectedStones(Collections.<Stone> emptyList()); view.setSelectedStones(Collections.<Stone> emptyList());
view.setInvalidStoneSets(Collections.<StoneSet> emptyList()); view.setInvalidStoneSets(Collections.<StoneSet> emptyList());
@ -356,6 +447,9 @@ public class RoundControl {
} }
} }
/**
* Ends the current round and emits an event setting the score
*/
void endOfRound() { void endOfRound() {
removeListeners(); removeListeners();
Score roundScore = score(); Score roundScore = score();
@ -363,12 +457,20 @@ public class RoundControl {
roundFinished = true; roundFinished = true;
} }
/**
* Removes all listeners form the connections
*/
private void removeListeners() { private void removeListeners() {
for (Connection c : connections) { for (Connection c : connections) {
c.remove(); c.remove();
} }
} }
/**
* Calculate the score for the current round and the total game score
*
* @return the new score
*/
private Score score() { private Score score() {
List<Boolean> winners = new ArrayList<Boolean>(); List<Boolean> winners = new ArrayList<Boolean>();
List<Integer> points = new ArrayList<Integer>(); List<Integer> points = new ArrayList<Integer>();
@ -393,10 +495,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;
@ -415,6 +519,18 @@ public class RoundControl {
return new Score(winners, points); return new Score(winners, points);
} }
/**
* Update the best score to find the winner in case of special game end
* (everybody still has stones on hand)
*
* @param bestScore
* of previous rounds
* @param stonePoints
* sum of points still left on hands
* @param size
* number of players in game (= size of score list in columns)
* @return Pair of maximum points and hand size
*/
private static Pair<Integer, Integer> updateBestScore( private static Pair<Integer, Integer> updateBestScore(
Pair<Integer, Integer> bestScore, int stonePoints, int size) { Pair<Integer, Integer> bestScore, int stonePoints, int size) {
if (bestScore.getFirst() == stonePoints) { if (bestScore.getFirst() == stonePoints) {
@ -435,6 +551,10 @@ public class RoundControl {
return restartRoundEvent; return restartRoundEvent;
} }
/**
* Redeal stones and restart round if a player was allowed to redeal and
* chose to do so
*/
private void redeal() { private void redeal() {
turnControl = null; turnControl = null;
for (Connection c : new ArrayList<Connection>(connections)) { for (Connection c : new ArrayList<Connection>(connections)) {

View file

@ -107,6 +107,13 @@ public class SaveControl {
this.roundState = roundState; this.roundState = roundState;
} }
/**
* Loads the specified file and sets game state and round state. If the file
* selected cannot be handled, an error will occur and show
*
* @param file
* to be loaded
*/
private void load(File file) { private void load(File file) {
try { try {
ObjectInputStream stream = new ObjectInputStream( ObjectInputStream stream = new ObjectInputStream(
@ -140,6 +147,13 @@ public class SaveControl {
return loadErrorEvent; return loadErrorEvent;
} }
/**
* Saves the current game state and round state to a file with the specified
* file name
*
* @param file
* file to save game in
*/
private void save(File file) { private void save(File file) {
if (gameState == null || gameSettings == null) { if (gameState == null || gameSettings == null) {
return; return;

View file

@ -25,9 +25,9 @@ public class SettingsControl extends AbstractSettingsControl {
* 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) {
super(view, settings); super(view, settings);
@ -48,8 +48,8 @@ public class SettingsControl extends AbstractSettingsControl {
} }
/** /**
* 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
*/ */
@ -96,8 +96,9 @@ public class SettingsControl extends AbstractSettingsControl {
view.getSettingsPanel().enableRemovePlayerButtons( view.getSettingsPanel().enableRemovePlayerButtons(
Collections.nCopies(settings.getPlayerList().size(), Collections.nCopies(settings.getPlayerList().size(),
enableRemoveButtons)); enableRemoveButtons));
view.getSettingsPanel().enableAddPlayerButton( view.getSettingsPanel()
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length); .enableAddPlayerButton(
settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
checkSettings(); checkSettings();
@ -109,6 +110,10 @@ public class SettingsControl extends AbstractSettingsControl {
view.getSettingsPanel().setGameSettings(settings); view.getSettingsPanel().setGameSettings(settings);
} }
/**
* Aborts the settings control and emits a start game event if settings have
* been approved
*/
private void startGame() { private void startGame() {
if (!checkSettings()) { if (!checkSettings()) {
return; return;