summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/SettingsControl.java40
-rw-r--r--src/jrummikub/model/GameSettings.java32
-rw-r--r--src/jrummikub/view/ISettingsPanel.java12
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java25
4 files changed, 93 insertions, 16 deletions
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
index ffd1911..9cb216d 100644
--- a/src/jrummikub/control/SettingsControl.java
+++ b/src/jrummikub/control/SettingsControl.java
@@ -216,7 +216,7 @@ public class SettingsControl {
for (PlayerSettings player : settings.getPlayerList()) {
if (player.getName().isEmpty()) {
view.getSettingsPanel().setError(
- ISettingsPanel.SettingsError.NO_PLAYER_NAME);
+ ISettingsPanel.SettingsError.NO_PLAYER_NAME_ERROR);
view.getSettingsPanel().enableStartGameButton(false);
return false;
}
@@ -226,16 +226,50 @@ 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);
+ view.getSettingsPanel()
+ .setError(
+ ISettingsPanel.SettingsError.DUPLICATE_PLAYER_NAME_ERROR);
view.getSettingsPanel().enableStartGameButton(false);
return false;
}
}
}
+ int totalStonesDealt = settings.getNumberOfStonesDealt()
+ * settings.getPlayerList().size();
+ int totalStones = settings.getHighestCard() * settings.getStoneSetNumber()
+ * settings.getStoneColors().size() + settings.getJokerNumber();
+
+ if (totalStones <= totalStonesDealt) {
+ view.getSettingsPanel().setError(
+ ISettingsPanel.SettingsError.NOT_ENOUGH_STONES_ERROR);
+ view.getSettingsPanel().enableStartGameButton(false);
+ return false;
+ }
+
view.getSettingsPanel().setError(ISettingsPanel.SettingsError.NO_ERROR);
view.getSettingsPanel().enableStartGameButton(true);
+
+ if (settings.getInitialMeldThreshold() >= 100) {
+ view.getSettingsPanel().setError(
+ ISettingsPanel.SettingsError.TOO_HIGH_THRESHOLD_WARNING);
+ return true;
+ }
+
+ boolean humanPlayerFound = false;
+ for (PlayerSettings player : settings.getPlayerList()) {
+ if (player.getTurnControlType() == TurnControlFactory.Type.HUMAN) {
+ humanPlayerFound = true;
+ break;
+ }
+ }
+
+ if (!humanPlayerFound) {
+ view.getSettingsPanel().setError(
+ ISettingsPanel.SettingsError.COMPUTER_PLAYERS_ONLY_WARNING);
+ return true;
+ }
+
return true;
}
diff --git a/src/jrummikub/model/GameSettings.java b/src/jrummikub/model/GameSettings.java
index 193188f..d571a93 100644
--- a/src/jrummikub/model/GameSettings.java
+++ b/src/jrummikub/model/GameSettings.java
@@ -17,7 +17,8 @@ public class GameSettings {
private int jokerPoints;
private int jokerNumber;
private int highestCard;
- private int stoneSets;
+ private int stoneSetNumber;
+ private int numberOfStonesDealt;
private boolean noLimits;
private Set<StoneColor> stoneColors;
@@ -29,7 +30,8 @@ public class GameSettings {
jokerPoints = 50;
jokerNumber = 2;
highestCard = 13;
- stoneSets = 2;
+ stoneSetNumber = 2;
+ numberOfStonesDealt = 14;
noLimits = false;
stoneColors = new HashSet<StoneColor>(Arrays.asList(BLACK, BLUE,
ORANGE, RED));
@@ -124,8 +126,8 @@ public class GameSettings {
*
* @return sets of stones in use
*/
- public int getStoneSets() {
- return stoneSets;
+ public int getStoneSetNumber() {
+ return stoneSetNumber;
}
/**
@@ -134,8 +136,8 @@ public class GameSettings {
* @param stoneSets
* sets of stones in use
*/
- public void setStoneSets(int stoneSets) {
- this.stoneSets = stoneSets;
+ public void setStoneSetNumber(int stoneSets) {
+ this.stoneSetNumber = stoneSets;
}
/**
@@ -175,4 +177,22 @@ public class GameSettings {
public void setStoneColors(Set<StoneColor> stoneColors) {
this.stoneColors = stoneColors;
}
+
+ /**
+ * Get number of stones dealt at game start
+ *
+ * @return numberOfStonesDealt
+ */
+ public int getNumberOfStonesDealt() {
+ return numberOfStonesDealt;
+ }
+
+ /**
+ * Set number of stones dealt at game start
+ *
+ * @param number
+ */
+ public void setNumberOfStonesDealt(int number) {
+ numberOfStonesDealt = number;
+ }
}
diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java
index d28a9b4..8c30c78 100644
--- a/src/jrummikub/view/ISettingsPanel.java
+++ b/src/jrummikub/view/ISettingsPanel.java
@@ -136,9 +136,17 @@ public interface ISettingsPanel {
/** Everything is ok */
NO_ERROR,
/** A player name is used twice */
- DUPLICATE_PLAYER_NAME,
+ DUPLICATE_PLAYER_NAME_ERROR,
/** A player has an empty name */
- NO_PLAYER_NAME
+ NO_PLAYER_NAME_ERROR,
+ /** More Stones than present would be dealed */
+ NOT_ENOUGH_STONES_ERROR,
+
+ // warnings
+ /** threshold higher 100 */
+ TOO_HIGH_THRESHOLD_WARNING,
+ /** Only computer players added */
+ COMPUTER_PLAYERS_ONLY_WARNING
}
/**
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index 02dfc10..a5792e7 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -112,14 +112,31 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
case NO_ERROR:
errorMessageLabel.setText(" ");
break;
- case DUPLICATE_PLAYER_NAME:
+ case DUPLICATE_PLAYER_NAME_ERROR:
errorMessageLabel
.setText("Jeder Spielername darf nur einmal verwendet werden.");
+ errorMessageLabel.setForeground(Color.RED);
break;
- case NO_PLAYER_NAME:
+ case NO_PLAYER_NAME_ERROR:
errorMessageLabel.setText("Jeder Spieler muss einen Namen haben.");
+ errorMessageLabel.setForeground(Color.RED);
+ break;
+ case NOT_ENOUGH_STONES_ERROR:
+ errorMessageLabel
+ .setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl.");
+ errorMessageLabel.setForeground(Color.RED);
+ break;
+ case COMPUTER_PLAYERS_ONLY_WARNING:
+ errorMessageLabel.setText("Es gibt keinen menschlichen Spieler.");
+ errorMessageLabel.setForeground(Color.ORANGE.darker());
+ break;
+ case TOO_HIGH_THRESHOLD_WARNING:
+ errorMessageLabel
+ .setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch");
+ errorMessageLabel.setForeground(Color.ORANGE.darker());
break;
}
+
}
@Override
@@ -284,7 +301,6 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
add(tabbedPane, c);
errorMessageLabel = new JLabel(" ");
- errorMessageLabel.setForeground(Color.RED);
c.weighty = 0;
add(errorMessageLabel, c);
@@ -313,8 +329,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
nameField.setText(settings.getName());
}
// playerType.setSelectedIndex(0);
- int index = Arrays.binarySearch(
- TurnControlFactory.Type.values(),
+ int index = Arrays.binarySearch(TurnControlFactory.Type.values(),
settings.getTurnControlType());
if (index != playerType.getSelectedIndex()) {
playerType.setSelectedIndex(index);