From c004a07a4267f3320d23f3d1d2cf483cd56f40b7 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 31 May 2011 01:50:56 +0200 Subject: Make highest value and number of stones dealt settable git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@337 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/SettingsControl.java | 29 +++++++++++++++++++++- src/jrummikub/model/GameSettings.java | 39 +++++++++++++++--------------- src/jrummikub/model/StoneHeap.java | 2 +- src/jrummikub/model/StoneSet.java | 12 ++++----- src/jrummikub/view/ISettingsPanel.java | 24 ++++++++++++------ src/jrummikub/view/impl/SettingsPanel.java | 38 ++++++++++++++++++++++++++--- 6 files changed, 106 insertions(+), 38 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java index f12f1ad..fd01613 100644 --- a/src/jrummikub/control/SettingsControl.java +++ b/src/jrummikub/control/SettingsControl.java @@ -2,12 +2,15 @@ package jrummikub.control; import java.awt.Color; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import jrummikub.control.turn.TurnControlFactory; import jrummikub.control.turn.TurnControlFactory.Type; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; +import jrummikub.model.StoneColor; import jrummikub.util.Connection; import jrummikub.util.Event1; import jrummikub.util.IEvent1; @@ -83,6 +86,30 @@ public class SettingsControl { update(); } })); + connections.add(view.getSettingsPanel().getChangeNumberOfStonesDealtEvent() + .add(new IListener1() { + @Override + public void handle(Integer value) { + settings.setNumberOfStonesDealt(value); + update(); + } + })); + connections.add(view.getSettingsPanel().getChangeHighestValueEvent() + .add(new IListener1() { + @Override + public void handle(Integer value) { + settings.setHighestValue(value); + update(); + } + })); + connections.add(view.getSettingsPanel().getChangeStoneColorsEvent() + .add(new IListener1>() { + @Override + public void handle(Set value) { + settings.setStoneColors(new HashSet(value)); + update(); + } + })); addPlayerSettingsListeners(); @@ -242,7 +269,7 @@ public class SettingsControl { int totalStonesDealt = settings.getNumberOfStonesDealt() * settings.getPlayerList().size(); - int totalStones = settings.getHighestCard() + int totalStones = settings.getHighestValue() * settings.getStoneSetNumber() * settings.getStoneColors().size() + settings.getJokerNumber(); diff --git a/src/jrummikub/model/GameSettings.java b/src/jrummikub/model/GameSettings.java index d571a93..f3cf69a 100644 --- a/src/jrummikub/model/GameSettings.java +++ b/src/jrummikub/model/GameSettings.java @@ -1,11 +1,12 @@ package jrummikub.model; +import static jrummikub.model.StoneColor.*; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Set; -import static jrummikub.model.StoneColor.*; /** * The overall game settings @@ -16,7 +17,7 @@ public class GameSettings { private int initialMeldThreshold; private int jokerPoints; private int jokerNumber; - private int highestCard; + private int highestValue; private int stoneSetNumber; private int numberOfStonesDealt; private boolean noLimits; @@ -29,12 +30,12 @@ public class GameSettings { initialMeldThreshold = 30; jokerPoints = 50; jokerNumber = 2; - highestCard = 13; + highestValue = 13; stoneSetNumber = 2; numberOfStonesDealt = 14; noLimits = false; - stoneColors = new HashSet(Arrays.asList(BLACK, BLUE, - ORANGE, RED)); + stoneColors = new HashSet(Arrays.asList(BLACK, BLUE, ORANGE, + RED)); } /** @@ -50,7 +51,7 @@ public class GameSettings { * Sets the initial meld threshold * * @param value - * the value to set + * the value to set */ public void setInitialMeldThreshold(int value) { initialMeldThreshold = value; @@ -69,7 +70,7 @@ public class GameSettings { * Sets the points counted for a joker * * @param value - * the value to set + * the value to set */ public void setJokerPoints(int value) { jokerPoints = value; @@ -103,22 +104,22 @@ public class GameSettings { } /** - * Return the highest card value in use + * Return the highest stone value in use * - * @return highest card value + * @return highest stone value */ - public int getHighestCard() { - return highestCard; + public int getHighestValue() { + return highestValue; } /** - * Set the highest card value in use + * Set the highest stone value in use * - * @param highestCard - * highest card value + * @param highestValue + * highest stone value */ - public void setHighestCard(int highestCard) { - this.highestCard = highestCard; + public void setHighestValue(int highestValue) { + this.highestValue = highestValue; } /** @@ -134,7 +135,7 @@ public class GameSettings { * Set the number of sets of stones in use * * @param stoneSets - * sets of stones in use + * sets of stones in use */ public void setStoneSetNumber(int stoneSets) { this.stoneSetNumber = stoneSets; @@ -153,7 +154,7 @@ public class GameSettings { * Set whether "No-Limits" rules are used * * @param noLimits - * use no limit rules + * use no limit rules */ public void setNoLimits(boolean noLimits) { this.noLimits = noLimits; @@ -172,7 +173,7 @@ public class GameSettings { * Set stone colors used * * @param stoneColors - * used stone colors + * used stone colors */ public void setStoneColors(Set stoneColors) { this.stoneColors = stoneColors; diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java index 27c8d01..b3c5fbe 100644 --- a/src/jrummikub/model/StoneHeap.java +++ b/src/jrummikub/model/StoneHeap.java @@ -23,7 +23,7 @@ public class StoneHeap { * */ public StoneHeap(GameSettings gameSettings) { heap = new ArrayList(); - for (int i = 1; i <= gameSettings.getHighestCard(); i++) { + for (int i = 1; i <= gameSettings.getHighestValue(); i++) { for (int j = 0; j < gameSettings.getStoneSetNumber(); j++) { for (StoneColor c : gameSettings.getStoneColors()) { heap.add(new Stone(i, c)); diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index efe7a2e..3324565 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -75,19 +75,19 @@ public class StoneSet implements Iterable, Sizeable { } if (nonJoker == -1) { - if (stones.size() > settings.getHighestCard()) { + if (stones.size() > settings.getHighestValue()) { return new Pair(INVALID, 0); } else if (stones.size() > settings.getStoneColors().size()) { return new Pair( RUN, - (settings.getHighestCard() * (settings.getHighestCard() + 1)) + (settings.getHighestValue() * (settings.getHighestValue() + 1)) / 2 - - (stones.size() - settings.getHighestCard()) - * (stones.size() - settings.getHighestCard() - 1) + - (stones.size() - settings.getHighestValue()) + * (stones.size() - settings.getHighestValue() - 1) / 2); } else { return new Pair(GROUP, stones.size() - * settings.getHighestCard()); + * settings.getHighestValue()); } } @@ -115,7 +115,7 @@ public class StoneSet implements Iterable, Sizeable { int startValue = stones.get(referencePosition).getValue() - referencePosition; int endValue = startValue + stones.size() - 1; - if (startValue < 1 || endValue > settings.getHighestCard()) { + if (startValue < 1 || endValue > settings.getHighestValue()) { return 0; } for (int i = 0; i < stones.size(); i++) { diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index 5c83f47..1d030fe 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -1,9 +1,11 @@ package jrummikub.view; import java.awt.Color; +import java.util.Set; import jrummikub.control.turn.TurnControlFactory; import jrummikub.model.GameSettings; +import jrummikub.model.StoneColor; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; @@ -34,8 +36,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 */ @@ -80,9 +82,15 @@ public interface ISettingsPanel { * @return the event */ public IEvent1 getChangeInitialMeldThresholdEvent(); - + public IEvent1 getChangeStoneSetNumberEvent(); + public IEvent1 getChangeNumberOfStonesDealtEvent(); + + public IEvent1 getChangeHighestValueEvent(); + + public IEvent1> getChangeStoneColorsEvent(); + /** * the start game event is emitted when the user wants to start the game * @@ -94,7 +102,7 @@ public interface ISettingsPanel { * Sets an error to display * * @param error - * the kind of error + * the kind of error */ public void setError(SettingsError error); @@ -102,7 +110,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); @@ -110,7 +118,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); @@ -118,7 +126,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); @@ -127,7 +135,7 @@ public interface ISettingsPanel { * Sets the game settings to display * * @param gameSettings - * the settings + * the settings */ public void setGameSettings(GameSettings gameSettings); diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index 5eb82fb..95089a3 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -17,6 +17,7 @@ import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; import javax.swing.Box; import javax.swing.BoxLayout; @@ -44,6 +45,7 @@ import jrummikub.control.turn.TurnControlFactory; import jrummikub.control.turn.TurnControlFactory.Type; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; +import jrummikub.model.StoneColor; import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.Event2; @@ -66,6 +68,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private JSpinner initialMeldThresholdSpinner; private JSpinner stoneSetNumberSpinner; + private JSpinner highestValueSpinner; + private JSpinner numberOfStonesDealtSpinner; private JSpinner jokerNumberSpinner; private Event startGameEvent = new Event(); @@ -77,6 +81,9 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private Event1 changeInitialMeldThresholdEvent = new Event1(); private Event1 changeJokerNumberEvent = new Event1(); private Event1 changeStoneSetNumberEvent = new Event1(); + private Event1 changeNumberOfStonesDealtEvent = new Event1(); + private Event1 changeHighestValueEvent = new Event1(); + private Event1> changeStoneColorsEvent = new Event1>(); @Override public IEvent getStartGameEvent() { @@ -113,6 +120,21 @@ class SettingsPanel extends JPanel implements ISettingsPanel { return changeStoneSetNumberEvent; } + @Override + public IEvent1 getChangeNumberOfStonesDealtEvent() { + return changeNumberOfStonesDealtEvent; + } + + @Override + public IEvent1 getChangeHighestValueEvent() { + return changeHighestValueEvent; + } + + @Override + public IEvent1> getChangeStoneColorsEvent() { + return changeStoneColorsEvent; + } + @Override public void setError(SettingsError error) { switch (error) { @@ -178,6 +200,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { initialMeldThresholdSpinner.setValue(gameSettings .getInitialMeldThreshold()); stoneSetNumberSpinner.setValue(gameSettings.getStoneSetNumber()); + highestValueSpinner.setValue(gameSettings.getHighestValue()); + numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt()); jokerNumberSpinner.setValue(gameSettings.getJokerNumber()); playerSettingsViewport.revalidate(); @@ -251,13 +275,21 @@ class SettingsPanel extends JPanel implements ISettingsPanel { stoneSetNumberSpinner = makeOptionSpinner(1, 1, 999, 1, changeStoneSetNumberEvent); - makeOptionLabel(2, "Jokeranzahl:"); - jokerNumberSpinner = makeOptionSpinner(2, 1, 999, 1, + makeOptionLabel(2, "H\u00f6chster Steinwert:"); + highestValueSpinner = makeOptionSpinner(2, 3, 99, 1, + changeHighestValueEvent); + + makeOptionLabel(3, "Anzahl Startsteine:"); + numberOfStonesDealtSpinner = makeOptionSpinner(3, 1, 999, 1, + changeNumberOfStonesDealtEvent); + + makeOptionLabel(4, "Jokeranzahl:"); + jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1, changeJokerNumberEvent); GridBagConstraints c = new GridBagConstraints(); c.gridx = 1; - c.gridy = 3; + c.gridy = 5; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; -- cgit v1.2.3