summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/SettingsControl.java77
1 files changed, 46 insertions, 31 deletions
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
index fd01613..8362d52 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;
@@ -46,8 +46,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
*/
@@ -59,9 +59,25 @@ public class SettingsControl {
* Start the operation of the settings control
*/
public void startSettings() {
+ addPlayerSettingsListeners();
+
+ addOptionListeners1();
+ addOptionListeners2();
+
+ connections.add(view.getSettingsPanel().getStartGameEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ startGame();
+ }
+ }));
+
+ view.showSettingsPanel(true);
+ }
+
+ 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);
@@ -94,6 +110,9 @@ public class SettingsControl {
update();
}
}));
+ }
+
+ private void addOptionListeners2() {
connections.add(view.getSettingsPanel().getChangeHighestValueEvent()
.add(new IListener1<Integer>() {
@Override
@@ -110,20 +129,9 @@ public class SettingsControl {
update();
}
}));
-
- addPlayerSettingsListeners();
-
- view.showSettingsPanel(true);
}
private void addPlayerSettingsListeners() {
- connections.add(view.getSettingsPanel().getStartGameEvent()
- .add(new IListener() {
- @Override
- public void handle() {
- startGame();
- }
- }));
connections.add(view.getSettingsPanel().getAddPlayerEvent()
.add(new IListener() {
@Override
@@ -193,8 +201,7 @@ public class SettingsControl {
break;
}
- settings.getPlayerList().add(
- new PlayerSettings("Spieler " + num, color));
+ settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color));
update();
}
@@ -235,9 +242,8 @@ public class SettingsControl {
private 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();
@@ -258,9 +264,8 @@ 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;
}
@@ -269,8 +274,7 @@ 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) {
@@ -280,13 +284,26 @@ public class SettingsControl {
return false;
}
+ if (settings.getStoneColors().size() < 3) {
+ view.getSettingsPanel().setError(
+ ISettingsPanel.SettingsError.NOT_ENOUGH_COLORS_ERROR);
+ view.getSettingsPanel().enableStartGameButton(false);
+ return false;
+ }
+
view.getSettingsPanel().setError(ISettingsPanel.SettingsError.NO_ERROR);
view.getSettingsPanel().enableStartGameButton(true);
+ checkWarnings();
+
+ return true;
+ }
+
+ private void checkWarnings() {
if (settings.getInitialMeldThreshold() >= 100) {
view.getSettingsPanel().setError(
ISettingsPanel.SettingsError.TOO_HIGH_THRESHOLD_WARNING);
- return true;
+ return;
}
boolean humanPlayerFound = false;
@@ -300,10 +317,8 @@ public class SettingsControl {
if (!humanPlayerFound) {
view.getSettingsPanel().setError(
ISettingsPanel.SettingsError.COMPUTER_PLAYERS_ONLY_WARNING);
- return true;
+ return;
}
-
- return true;
}
private void startGame() {