summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-06-11 04:09:29 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-06-11 04:09:29 +0200
commit2c4d2ba28baa858e9fb3eed52a9b76334330bcdf (patch)
tree600f91a2f310232d308eb5a198120510e49caa22 /src
parent8b1e09f0257de32213debc4bcfcebfc061d51bb2 (diff)
downloadJRummikub-2c4d2ba28baa858e9fb3eed52a9b76334330bcdf.tar
JRummikub-2c4d2ba28baa858e9fb3eed52a9b76334330bcdf.zip
No Limits implementiert und getestet, geht
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@413 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/SettingsControl.java39
-rw-r--r--src/jrummikub/model/StoneSet.java44
-rw-r--r--src/jrummikub/view/ISettingsPanel.java22
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java149
4 files changed, 161 insertions, 93 deletions
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
index 6f4e149..4351c59 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) {
@@ -138,6 +140,15 @@ public class SettingsControl {
update();
}
}));
+
+ connections.add(view.getSettingsPanel().getChangeNoLimitsEvent()
+ .add(new IListener1<Boolean>() {
+ @Override
+ public void handle(Boolean value) {
+ settings.setNoLimits(value);
+ update();
+ }
+ }));
}
private void addPlayerSettingsListeners() {
@@ -210,7 +221,8 @@ public class SettingsControl {
break;
}
- settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color));
+ settings.getPlayerList().add(
+ new PlayerSettings("Spieler " + num, color));
update();
}
@@ -251,8 +263,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();
@@ -273,8 +286,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;
}
@@ -283,7 +297,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) {
diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java
index edd6f3f..c1d7a5d 100644
--- a/src/jrummikub/model/StoneSet.java
+++ b/src/jrummikub/model/StoneSet.java
@@ -85,17 +85,20 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
if (nonJoker == -1) {
if (stones.size() > settings.getHighestValue()
- && stones.size() > settings.getStoneColors().size()) {
+ && stones.size() > settings.getStoneColors().size()
+ && !settings.isNoLimits()) {
return new Pair<Type, Integer>(INVALID, 0);
} else if (stones.size() > settings.getStoneColors().size()) {
- return new Pair<Type, Integer>(
- RUN,
- (settings.getHighestValue() * (settings
- .getHighestValue() + 1))
- / 2
- - (stones.size() - settings.getHighestValue())
- * (stones.size() - settings.getHighestValue() - 1)
- / 2);
+ 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());
@@ -126,24 +129,33 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable {
int startValue = stones.get(referencePosition).getValue()
- referencePosition;
int endValue = startValue + stones.size() - 1;
- if (startValue < 1 || endValue > settings.getHighestValue()) {
- return 0;
+ if (!settings.isNoLimits()) {
+ if (startValue < 1 || endValue > settings.getHighestValue()) {
+ return 0;
+ }
}
+ int value = 0;
for (int i = 0; i < stones.size(); i++) {
+ int expectedValue = i + startValue;
+ while (expectedValue < 1) {
+ expectedValue += settings.getHighestValue();
+ }
+ while (expectedValue > settings.getHighestValue()) {
+ expectedValue -= settings.getHighestValue();
+ }
+ value += expectedValue;
+
if (stones.get(i).isJoker()) {
continue;
}
if (stones.get(i).getColor() != runColor) {
return 0;
}
- if (stones.get(i).getValue() != i + startValue) {
+
+ if (stones.get(i).getValue() != expectedValue) {
return 0;
}
}
- int value = 0;
- for (int i = 0; i < stones.size(); i++) {
- value += startValue + i;
- }
return value;
}
diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java
index 09b0394..bc2593d 100644
--- a/src/jrummikub/view/ISettingsPanel.java
+++ b/src/jrummikub/view/ISettingsPanel.java
@@ -6,6 +6,7 @@ import java.util.Set;
import jrummikub.control.turn.TurnControlFactory;
import jrummikub.model.GameSettings;
import jrummikub.model.StoneColor;
+import jrummikub.util.Event1;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
import jrummikub.util.IEvent2;
@@ -36,8 +37,8 @@ public interface ISettingsPanel {
};
/**
- * The add player event is emitted when the user wants to add a player to the
- * player list
+ * The add player event is emitted when the user wants to add a player to
+ * the player list
*
* @return the event
*/
@@ -84,8 +85,8 @@ public interface ISettingsPanel {
public IEvent1<Integer> getChangeInitialMeldThresholdEvent();
/**
- * The change StoneSet number event is emitted when the user wants to use more
- * or less than 2 StoneSets per color
+ * The change StoneSet number event is emitted when the user wants to use
+ * more or less than 2 StoneSets per color
*
* @return number of SoneSets
*/
@@ -126,7 +127,7 @@ public interface ISettingsPanel {
* Sets an error to display
*
* @param error
- * the kind of error
+ * the kind of error
*/
public void setError(SettingsError error);
@@ -134,7 +135,7 @@ public interface ISettingsPanel {
* Enables or disables the start game button
*
* @param enable
- * specifies if the button is to be enabled or disabled
+ * specifies if the button is to be enabled or disabled
*/
public void enableStartGameButton(boolean enable);
@@ -142,7 +143,7 @@ public interface ISettingsPanel {
* Enables or disables the add player button
*
* @param enable
- * specifies if the button is to be enabled or disabled
+ * specifies if the button is to be enabled or disabled
*/
public void enableAddPlayerButton(boolean enable);
@@ -150,7 +151,7 @@ public interface ISettingsPanel {
* Enables or disables the remove player buttons
*
* @param enable
- * specifies if the buttons are to be enabled or disabled
+ * specifies if the buttons are to be enabled or disabled
*/
public void enableRemovePlayerButtons(boolean enable);
@@ -159,7 +160,7 @@ public interface ISettingsPanel {
* Sets the game settings to display
*
* @param gameSettings
- * the settings
+ * the settings
*/
public void setGameSettings(GameSettings gameSettings);
@@ -172,6 +173,8 @@ public interface ISettingsPanel {
public IEvent1<Integer> getChangeTimeEvent();
+ public IEvent1<Boolean> getChangeNoLimitsEvent();
+
/**
* Specifies the different kinds of settings errors that can be displayed
*/
@@ -193,4 +196,5 @@ public interface ISettingsPanel {
/** Only computer players added */
COMPUTER_PLAYERS_ONLY_WARNING
}
+
} \ No newline at end of file
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index d7d9069..9536838 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -26,6 +26,7 @@ import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.JButton;
+import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
@@ -67,6 +68,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private JButton addPlayerButton;
private JLabel errorMessageLabel;
private JButton startButton;
+ private JCheckBox noLimitsBox;
private boolean removeButtonsEnabled = true;
private List<PlayerSettingsPanel> playerSettingsPanels = new ArrayList<PlayerSettingsPanel>();
@@ -96,6 +98,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private Event1<Integer> changeHighestValueEvent = new Event1<Integer>();
private Event1<Set<StoneColor>> changeStoneColorsEvent = new Event1<Set<StoneColor>>();
private Event1<Integer> changeTimeEvent = new Event1<Integer>();
+ private Event1<Boolean> changeNoLimitsEvent = new Event1<Boolean>();
@Override
public IEvent getStartGameEvent() {
@@ -161,11 +164,16 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
@Override
- public Event1<Integer> getChangeTimeEvent() {
+ public IEvent1<Integer> getChangeTimeEvent() {
return changeTimeEvent;
}
@Override
+ public IEvent1<Boolean> getChangeNoLimitsEvent() {
+ return changeNoLimitsEvent;
+ }
+
+ @Override
public IEvent1<Set<StoneColor>> getChangeStoneColorsEvent() {
return changeStoneColorsEvent;
}
@@ -173,37 +181,37 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override
public void setError(SettingsError error) {
switch (error) {
- case NO_ERROR:
- errorMessageLabel.setText(" ");
- break;
- case DUPLICATE_PLAYER_NAME_ERROR:
- errorMessageLabel
- .setText("Jeder Spielername darf nur einmal verwendet werden.");
- errorMessageLabel.setForeground(Color.RED);
- break;
- 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 NOT_ENOUGH_COLORS_ERROR:
- errorMessageLabel
- .setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden.");
- 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;
+ case NO_ERROR:
+ errorMessageLabel.setText(" ");
+ break;
+ case DUPLICATE_PLAYER_NAME_ERROR:
+ errorMessageLabel
+ .setText("Jeder Spielername darf nur einmal verwendet werden.");
+ errorMessageLabel.setForeground(Color.RED);
+ break;
+ 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 NOT_ENOUGH_COLORS_ERROR:
+ errorMessageLabel
+ .setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden.");
+ 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;
}
}
@@ -228,7 +236,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override
public void setGameSettings(GameSettings gameSettings) {
- while (playerSettingsPanels.size() > gameSettings.getPlayerList().size()) {
+ while (playerSettingsPanels.size() > gameSettings.getPlayerList()
+ .size()) {
removePlayerSettingsPanel();
}
@@ -236,13 +245,15 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i));
}
- initialMeldThresholdSpinner
- .setValue(gameSettings.getInitialMeldThreshold());
+ initialMeldThresholdSpinner.setValue(gameSettings
+ .getInitialMeldThreshold());
stoneSetNumberSpinner.setValue(gameSettings.getStoneSetNumber());
highestValueSpinner.setValue(gameSettings.getHighestValue());
- numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt());
+ numberOfStonesDealtSpinner.setValue(gameSettings
+ .getNumberOfStonesDealt());
jokerNumberSpinner.setValue(gameSettings.getJokerNumber());
timeSpinner.setValue(gameSettings.getTime());
+ noLimitsBox.setSelected(gameSettings.isNoLimits());
for (StoneColor color : StoneColor.values()) {
colorButtons.get(color).getModel()
@@ -268,8 +279,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void removePlayerSettingsPanel() {
- PlayerSettingsPanel p = playerSettingsPanels.remove(playerSettingsPanels
- .size() - 1);
+ PlayerSettingsPanel p = playerSettingsPanels
+ .remove(playerSettingsPanels.size() - 1);
playerSettingsViewport.remove(p);
}
@@ -291,7 +302,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
playerSettingsViewport.add(addPlayerPanel);
addPlayerButton = new JButton("+");
- addPlayerButton.setFont(addPlayerButton.getFont().deriveFont(Font.BOLD));
+ addPlayerButton
+ .setFont(addPlayerButton.getFont().deriveFont(Font.BOLD));
addPlayerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -328,17 +340,21 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
changeNumberOfStonesDealtEvent);
makeOptionLabel(4, "Jokeranzahl:");
- jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1, changeJokerNumberEvent);
+ jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1,
+ changeJokerNumberEvent);
makeOptionLabel(5, "Zeit für Spielzug:");
timeSpinner = makeOptionSpinner(5, 1, 999, 1, changeTimeEvent);
- makeOptionLabel(6, "Steinfarben:");
- createColorSelectionPanel(6);
+ makeOptionLabel(6, "No Limits:");
+ noLimitsBox = makeOptionCheckbox(6, changeNoLimitsEvent);
+
+ makeOptionLabel(7, "Steinfarben:");
+ createColorSelectionPanel(7);
GridBagConstraints c = new GridBagConstraints();
c.gridx = 1;
- c.gridy = 7;
+ c.gridy = 8;
c.fill = GridBagConstraints.BOTH;
c.weightx = 1;
c.weighty = 1;
@@ -388,6 +404,24 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
changeStoneColorsEvent.emit(colors);
}
+ private JCheckBox makeOptionCheckbox(int row,
+ final Event1<Boolean> targetEvent) {
+ GridBagConstraints c = new GridBagConstraints();
+ c.anchor = GridBagConstraints.WEST;
+ c.gridx = 1;
+ c.gridy = row;
+ c.insets = new Insets(2, 2, 2, 2);
+ final JCheckBox box = new JCheckBox();
+ box.addChangeListener(new ChangeListener() {
+ @Override
+ public void stateChanged(ChangeEvent e) {
+ targetEvent.emit(box.isSelected());
+ }
+ });
+ optionsPanel.add(box, c);
+ return box;
+ }
+
private JSpinner makeOptionSpinner(int row, int min, int max, int step,
final Event1<Integer> targetEvent) {
GridBagConstraints c = new GridBagConstraints();
@@ -397,8 +431,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.insets = new Insets(2, 2, 2, 2);
final JSpinner spinner = new JSpinner();
spinner.setModel(new SpinnerNumberModel(min, min, max, step));
- spinner
- .setPreferredSize(new Dimension(60, spinner.getMinimumSize().height));
+ spinner.setPreferredSize(new Dimension(60,
+ spinner.getMinimumSize().height));
spinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
@@ -458,8 +492,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.gridwidth = GridBagConstraints.REMAINDER;
addButton("Netzwerkspiel...", networkGameEvent, c);
- setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
- 10, 10, 10, 10)));
+ setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
+ new EmptyBorder(10, 10, 10, 10)));
}
void resetTabbedPane() {
@@ -496,8 +530,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
if (index != playerType.getSelectedIndex()) {
playerType.setSelectedIndex(index);
}
- colorButton
- .setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2));
+ colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(),
+ 16, 2));
}
public void enableRemoveButton(boolean enable) {
@@ -545,7 +579,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.gridy = 0;
add(colorButton, c);
- nameField.getDocument().addDocumentListener(new NameChangeListener());
+ nameField.getDocument().addDocumentListener(
+ new NameChangeListener());
c2.gridy = 0;
c2.weightx = 1;
c2.fill = GridBagConstraints.HORIZONTAL;
@@ -578,8 +613,9 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public Dimension getPreferredSize() {
Dimension preferredSize = super.getPreferredSize();
for (Component component : this.getComponents()) {
- preferredSize
- .setSize(preferredSize.width, Math.max(preferredSize.height,
+ preferredSize.setSize(
+ preferredSize.width,
+ Math.max(preferredSize.height,
component.getPreferredSize().height));
}
return preferredSize;
@@ -589,8 +625,9 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
public Dimension getMaximumSize() {
Dimension preferredSize = super.getPreferredSize();
for (Component component : this.getComponents()) {
- preferredSize
- .setSize(Integer.MAX_VALUE, Math.max(preferredSize.height,
+ preferredSize.setSize(
+ Integer.MAX_VALUE,
+ Math.max(preferredSize.height,
component.getPreferredSize().height));
}
return preferredSize;
@@ -605,8 +642,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
}
private void changeType() {
- changePlayerTypeEvent.emit(playerNumber,
- TurnControlFactory.Type.values()[playerType.getSelectedIndex()]);
+ changePlayerTypeEvent.emit(playerNumber, TurnControlFactory.Type
+ .values()[playerType.getSelectedIndex()]);
}
private void remove() {