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
This commit is contained in:
Matthias Schiffer 2011-05-31 01:50:56 +02:00
parent c78e8e6448
commit c004a07a42
11 changed files with 190 additions and 52 deletions

View file

@ -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<StoneColor>(Arrays.asList(BLACK, BLUE,
ORANGE, RED));
stoneColors = new HashSet<StoneColor>(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<StoneColor> stoneColors) {
this.stoneColors = stoneColors;

View file

@ -23,7 +23,7 @@ public class StoneHeap {
* */
public StoneHeap(GameSettings gameSettings) {
heap = new ArrayList<Stone>();
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));

View file

@ -75,19 +75,19 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
}
if (nonJoker == -1) {
if (stones.size() > settings.getHighestCard()) {
if (stones.size() > settings.getHighestValue()) {
return new Pair<Type, Integer>(INVALID, 0);
} else if (stones.size() > settings.getStoneColors().size()) {
return new Pair<Type, Integer>(
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<Type, Integer>(GROUP, stones.size()
* settings.getHighestCard());
* settings.getHighestValue());
}
}
@ -115,7 +115,7 @@ public class StoneSet implements Iterable<Stone>, 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++) {