summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-05-31 00:58:46 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-05-31 00:58:46 +0200
commitf22ff5f0f1d8f9838c30943bde658ca3f282bbc8 (patch)
tree4e3a34af00086ca862345c4677e69aaed04f3e49 /src/jrummikub
parentd66d73ea8f9d660d14e3ef80e716ac1628704fe4 (diff)
downloadJRummikub-f22ff5f0f1d8f9838c30943bde658ca3f282bbc8.tar
JRummikub-f22ff5f0f1d8f9838c30943bde658ca3f282bbc8.zip
Tests für Sets mit mehr Farben, mehr Values, ...
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@332 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/RoundControl.java24
-rw-r--r--src/jrummikub/model/RoundState.java2
-rw-r--r--src/jrummikub/model/StoneColor.java10
-rw-r--r--src/jrummikub/model/StoneHeap.java23
-rw-r--r--src/jrummikub/model/StoneSet.java6
-rw-r--r--src/jrummikub/model/Table.java21
-rw-r--r--src/jrummikub/view/impl/StonePainter.java82
7 files changed, 103 insertions, 65 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 5874532..e04327f 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -78,22 +78,23 @@ public class RoundControl {
}
private void prepareTurn() {
- boolean isHuman = roundState.getActivePlayer().getPlayerSettings().getTurnControlType() == HUMAN;
+ boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
+ .getTurnControlType() == HUMAN;
clonedTable = (ITable) roundState.getTable().clone();
-
+
if (isHuman) {
view.enableStartTurnPanel(true);
} else {
view.enableThinkPanel(true);
}
-
+
view.getTablePanel().setStoneSets(clonedTable);
view.setCurrentPlayerName(roundState.getActivePlayer()
.getPlayerSettings().getName());
view.setCurrentPlayerColor(roundState.getActivePlayer()
.getPlayerSettings().getColor());
view.setHasLaidOut(roundState.getActivePlayer().getLaidOut());
-
+
if (!isHuman)
startTurn();
}
@@ -101,7 +102,8 @@ public class RoundControl {
private void startTurn() {
if (turnControl != null)
return;
- boolean isHuman = roundState.getActivePlayer().getPlayerSettings().getTurnControlType() == HUMAN;
+ boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
+ .getTurnControlType() == HUMAN;
boolean inspectOnly = roundState.getTurnNumber() < 1;
boolean mayRedeal = inspectOnly
&& roundState.getActivePlayer().getHand()
@@ -110,10 +112,11 @@ public class RoundControl {
if (isHuman) {
view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
}
- turnControl = TurnControlFactory.getFactory(roundState.getActivePlayer()
- .getPlayerSettings().getTurnControlType()).create();
- turnControl.setup(roundState.getActivePlayer(), clonedTable,
- view, inspectOnly, mayRedeal);
+ turnControl = TurnControlFactory.getFactory(
+ roundState.getActivePlayer().getPlayerSettings()
+ .getTurnControlType()).create();
+ turnControl.setup(roundState.getActivePlayer(), clonedTable, view,
+ inspectOnly, mayRedeal);
turnControl.getEndOfTurnEvent().add(new IListener() {
@Override
public void handle() {
@@ -148,7 +151,8 @@ public class RoundControl {
int totalValue = 0;
for (StoneSet set : newSets) {
- totalValue += set.classify().getSecond();
+ totalValue += set.classify(roundState.getGameSettings())
+ .getSecond();
}
return totalValue == 0
diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java
index 9f1f7be..01d67d3 100644
--- a/src/jrummikub/model/RoundState.java
+++ b/src/jrummikub/model/RoundState.java
@@ -23,7 +23,7 @@ public class RoundState implements IRoundState {
public RoundState(GameSettings gameSettings) {
this.gameSettings = gameSettings;
- table = new Table();
+ table = new Table(gameSettings);
players = new ArrayList<Player>();
for (PlayerSettings playerSettings : gameSettings.getPlayerList()) {
diff --git a/src/jrummikub/model/StoneColor.java b/src/jrummikub/model/StoneColor.java
index 6b1807b..47c5227 100644
--- a/src/jrummikub/model/StoneColor.java
+++ b/src/jrummikub/model/StoneColor.java
@@ -9,5 +9,13 @@ public enum StoneColor {
/** */
BLUE,
/** */
- RED
+ RED,
+ /** */
+ GREEN,
+ /** */
+ VIOLET,
+ /** */
+ BROWN,
+ /** */
+ WHITE
}
diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java
index 8199672..27c8d01 100644
--- a/src/jrummikub/model/StoneHeap.java
+++ b/src/jrummikub/model/StoneHeap.java
@@ -3,7 +3,6 @@ package jrummikub.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.EnumSet;
import java.util.List;
import java.util.Random;
@@ -24,21 +23,25 @@ public class StoneHeap {
* */
public StoneHeap(GameSettings gameSettings) {
heap = new ArrayList<Stone>();
- for (int i = 1; i <= 13; i++) {
+ for (int i = 1; i <= gameSettings.getHighestCard(); i++) {
for (int j = 0; j < gameSettings.getStoneSetNumber(); j++) {
- for (StoneColor c : EnumSet.allOf(StoneColor.class)) {
+ for (StoneColor c : gameSettings.getStoneColors()) {
heap.add(new Stone(i, c));
}
}
}
// Joker
-
- ArrayList<StoneColor> jokerColors = new ArrayList<StoneColor>(Arrays.asList(StoneColor.values()));
-
- StoneColor temp = jokerColors.get(1);
- jokerColors.set(1, jokerColors.get(3));
- jokerColors.set(3, temp);
-
+
+ ArrayList<StoneColor> jokerColors = new ArrayList<StoneColor>(
+ Arrays.asList(StoneColor.values()));
+ jokerColors.retainAll(gameSettings.getStoneColors());
+
+ if (jokerColors.size() >= 4) {
+ StoneColor temp = jokerColors.get(1);
+ jokerColors.set(1, jokerColors.get(3));
+ jokerColors.set(3, temp);
+ }
+
int jokersLeft = gameSettings.getJokerNumber();
done: while (true) {
for (StoneColor c : jokerColors) {
diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java
index 2700889..3d6e49e 100644
--- a/src/jrummikub/model/StoneSet.java
+++ b/src/jrummikub/model/StoneSet.java
@@ -51,8 +51,8 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
*
* @return true when the set is valid according to the rules
*/
- public boolean isValid() {
- return classify().getFirst() != INVALID;
+ public boolean isValid(GameSettings settings) {
+ return classify(settings).getFirst() != INVALID;
}
/**
@@ -62,7 +62,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable {
* @return GROUP or RUN for valid sets, INVALID otherwise
*/
- public Pair<Type, Integer> classify() {
+ public Pair<Type, Integer> classify(GameSettings settings) {
if (stones.size() < 3) {
return new Pair<Type, Integer>(INVALID, 0);
}
diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java
index a3e25eb..87c360c 100644
--- a/src/jrummikub/model/Table.java
+++ b/src/jrummikub/model/Table.java
@@ -5,6 +5,7 @@ import jrummikub.util.Pair;
/** Class administering the {@link Stone}s on the game-Table */
public class Table extends StoneTray<StoneSet> implements ITable {
+ private GameSettings gameSettings;
private static class StoneInfo {
StoneSet set;
@@ -18,11 +19,15 @@ public class Table extends StoneTray<StoneSet> implements ITable {
}
}
+ public Table(GameSettings settings) {
+ gameSettings = settings;
+ }
+
/**
* Removes {@link Stone} from the Table
*
* @param stone
- * stone to pick up
+ * stone to pick up
*/
@Override
public void pickUpStone(Stone stone) {
@@ -69,21 +74,21 @@ public class Table extends StoneTray<StoneSet> implements ITable {
return info.set;
}
- private void splitSet(StoneSet set, Position setPosition,
- int stonePosition) {
+ private void splitSet(StoneSet set, Position setPosition, int stonePosition) {
pickUp(set);
Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition);
- Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond().splitAt(1);
+ Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond()
+ .splitAt(1);
StoneSet leftSet = firstSplit.getFirst();
StoneSet rightSet = secondSplit.getSecond();
- if (set.classify().getFirst() == StoneSet.Type.RUN) {
+ if (set.classify(gameSettings).getFirst() == StoneSet.Type.RUN) {
Position leftPosition, rightPosition;
leftPosition = setPosition;
- rightPosition = new Position(setPosition.getX() + stonePosition + 1,
- setPosition.getY());
+ rightPosition = new Position(
+ setPosition.getX() + stonePosition + 1, setPosition.getY());
drop(leftSet, leftPosition);
drop(rightSet, rightPosition);
@@ -105,7 +110,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
@Override
public boolean isValid() {
for (Pair<StoneSet, Position> i : this) {
- if (!i.getFirst().isValid()) {
+ if (!i.getFirst().isValid(gameSettings)) {
return false;
}
}
diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java
index 030fdea..d9bbdba 100644
--- a/src/jrummikub/view/impl/StonePainter.java
+++ b/src/jrummikub/view/impl/StonePainter.java
@@ -60,7 +60,8 @@ class StonePainter {
int g = (int) (color.getGreen() * BRIGHTER_SCALE);
int b = (int) (color.getBlue() * BRIGHTER_SCALE);
- return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
+ return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
+ : b);
}
private static Color hover(Color color) {
@@ -68,19 +69,28 @@ class StonePainter {
int g = (int) (color.getGreen() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
int b = (int) (color.getBlue() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
- return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
+ return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
+ : b);
}
private static Color getColor(StoneColor color) {
switch (color) {
- case BLACK:
- return new Color(0.15f, 0.15f, 0.15f);
- case BLUE:
- return new Color(0.0f, 0.0f, 1.0f);
- case ORANGE:
- return new Color(1.0f, 0.4f, 0.0f);
- case RED:
- return new Color(0.9f, 0.0f, 0.25f);
+ case BLACK:
+ return new Color(0.15f, 0.15f, 0.15f);
+ case BLUE:
+ return new Color(0.0f, 0.0f, 1.0f);
+ case ORANGE:
+ return new Color(1.0f, 0.4f, 0.0f);
+ case RED:
+ return new Color(0.9f, 0.0f, 0.25f);
+ case BROWN:
+ return new Color(0.5f, 0.25f, 0.0f);
+ case GREEN:
+ return new Color(0.0f, 0.75f, 0.0f);
+ case VIOLET:
+ return new Color(0.75f, 0.325f, 0.75f);
+ case WHITE:
+ return new Color(1.0f, 1.0f, 1.0f);
}
return null;
@@ -90,7 +100,7 @@ class StonePainter {
* Sets the new grid scale
*
* @param scale
- * the new scale
+ * the new scale
*/
public void setScale(float scale) {
this.scale = scale;
@@ -104,9 +114,9 @@ class StonePainter {
/**
* @param x
- * x position in screen coordinates
+ * x position in screen coordinates
* @param y
- * y position in screen coordinates
+ * y position in screen coordinates
* @return position in grid coordinates
*/
public Position calculatePosition(int x, int y) {
@@ -178,23 +188,29 @@ class StonePainter {
Color hoveredFg = hover(defaultFg);
Color hoveredSelectedFg = hover(selectedFg);
- defaultStones.put(color, prepaintColor(defaultFg, defaultBackground));
- selectedStones.put(color, prepaintColor(selectedFg, selectedBackground));
- hoveredStones.put(color, prepaintColor(hoveredFg, hoveredBackground));
- hoveredSelectedStones.put(color,
- prepaintColor(hoveredSelectedFg, hoveredSelectedBackground));
+ defaultStones.put(color,
+ prepaintColor(defaultFg, defaultBackground));
+ selectedStones.put(color,
+ prepaintColor(selectedFg, selectedBackground));
+ hoveredStones.put(color,
+ prepaintColor(hoveredFg, hoveredBackground));
+ hoveredSelectedStones
+ .put(color,
+ prepaintColor(hoveredSelectedFg,
+ hoveredSelectedBackground));
}
}
/**
* @param scale
- * the scaling factor for the grid coordinates
+ * the scaling factor for the grid coordinates
*/
StonePainter(float scale) {
setScale(scale);
}
- private void paintStoneBackground(Graphics2D g, Rectangle r, Color background) {
+ private void paintStoneBackground(Graphics2D g, Rectangle r,
+ Color background) {
// Paint background
g.setColor(background);
g.fillRect(r.x, r.y, r.width, r.height);
@@ -294,8 +310,9 @@ class StonePainter {
pos + (fm.getAscent() - fm.getDescent()) / 2 + 1);
}
g.setColor(color);
- g.drawString(value, (int) (r.x + r.width / 2 - stringRect.getWidth() / 2),
- pos + (fm.getAscent() - fm.getDescent()) / 2);
+ g.drawString(value,
+ (int) (r.x + r.width / 2 - stringRect.getWidth() / 2), pos
+ + (fm.getAscent() - fm.getDescent()) / 2);
}
private void paintCircle(Graphics2D g, Rectangle r, Color background) {
@@ -304,26 +321,27 @@ class StonePainter {
// Paint circle
g.setColor(background.darker());
- g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50, 170);
+ g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50,
+ 170);
g.setColor(brighter(background));
- g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size, size,
- -130, 170);
+ g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size,
+ size, -130, 170);
}
/**
* Paints a stone
*
* @param g
- * the graphics context to paint the stone on
+ * the graphics context to paint the stone on
* @param stone
- * the stone to paint
+ * the stone to paint
* @param p
- * the position of the stone
+ * the position of the stone
* @param selected
- * if selected is true the stone will be painted darker
+ * if selected is true the stone will be painted darker
* @param hovered
- * if hovered is true the stone will be painted brighter
+ * if hovered is true the stone will be painted brighter
*/
public void paintStone(Graphics2D g, Stone stone, Position p,
boolean selected, boolean hovered) {
@@ -350,8 +368,8 @@ class StonePainter {
if (stone.isJoker()) {
g.drawImage(stoneMap.get(stone.getColor()).get(0), x, y, null);
} else {
- g.drawImage(stoneMap.get(stone.getColor()).get(stone.getValue()), x, y,
- null);
+ g.drawImage(stoneMap.get(stone.getColor()).get(stone.getValue()),
+ x, y, null);
}
}
}