diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/jrummikub/model/GameSettings.java | 23 | ||||
-rw-r--r-- | src/jrummikub/model/Hand.java | 20 | ||||
-rw-r--r-- | src/jrummikub/model/IHand.java | 9 | ||||
-rw-r--r-- | src/jrummikub/model/Player.java | 4 | ||||
-rw-r--r-- | src/jrummikub/model/RoundState.java | 4 |
5 files changed, 54 insertions, 6 deletions
diff --git a/src/jrummikub/model/GameSettings.java b/src/jrummikub/model/GameSettings.java index b5079d4..7d525c6 100644 --- a/src/jrummikub/model/GameSettings.java +++ b/src/jrummikub/model/GameSettings.java @@ -10,12 +10,14 @@ public class GameSettings { private List<PlayerSettings> players = new ArrayList<PlayerSettings>(); private int initialMeldThreshold; + private int jokerPoints; /** * Creates new GameSettings with default values */ public GameSettings() { initialMeldThreshold = 30; + jokerPoints = 50; } /** @@ -31,7 +33,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; @@ -45,4 +47,23 @@ public class GameSettings { public int getInitialMeldThreshold() { return initialMeldThreshold; } + + /** + * Sets the points counted for a joker + * + * @param value + * the value to set + */ + public void setJokerPoints(int value) { + jokerPoints = value; + } + + /** + * Returns the points counted for a joker + * + * @return the points + */ + public int getJokerPoints() { + return jokerPoints; + } } diff --git a/src/jrummikub/model/Hand.java b/src/jrummikub/model/Hand.java index ab5eb19..35ea49f 100644 --- a/src/jrummikub/model/Hand.java +++ b/src/jrummikub/model/Hand.java @@ -10,6 +10,12 @@ public class Hand extends StoneTray<Stone> implements IHand { * The width of the hand */ public final static int WIDTH = 14; + + private GameSettings settings; + + public Hand(GameSettings settings) { + this.settings = settings; + } @Override public int getFreeRowSpace(int row) { @@ -54,4 +60,18 @@ public class Hand extends StoneTray<Stone> implements IHand { } } } + + public int getStonePoints() { + int points = 0; + + for (Pair<Stone, Position> entry : this) { + if (entry.getFirst().isJoker()) { + points += settings.getJokerPoints(); + } else { + points += entry.getFirst().getValue(); + } + } + + return points; + } } diff --git a/src/jrummikub/model/IHand.java b/src/jrummikub/model/IHand.java index dafa9c7..ec49489 100644 --- a/src/jrummikub/model/IHand.java +++ b/src/jrummikub/model/IHand.java @@ -16,8 +16,15 @@ public interface IHand extends IStoneTray<Stone> { * Gets the amount of free space in a hand row
*
* @param row
- * the row number
+ * the row number
* @return the number of stones that can fit into the row
*/
int getFreeRowSpace(int row);
+
+ /**
+ * Get the accumulated number of points of stones in the hand
+ *
+ * @return points
+ */
+ int getStonePoints();
}
diff --git a/src/jrummikub/model/Player.java b/src/jrummikub/model/Player.java index d10992e..6d3e6d6 100644 --- a/src/jrummikub/model/Player.java +++ b/src/jrummikub/model/Player.java @@ -12,10 +12,10 @@ public class Player implements IPlayer { * @param settings * the player settings */ - public Player(PlayerSettings settings) { + public Player(PlayerSettings settings, GameSettings gameSettings) { this.settings = settings; - hand = new Hand(); + hand = new Hand(gameSettings); laidOut = false; } diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java index 076fd00..c32c3c0 100644 --- a/src/jrummikub/model/RoundState.java +++ b/src/jrummikub/model/RoundState.java @@ -26,7 +26,7 @@ public class RoundState implements IRoundState { players = new ArrayList<Player>(); for (PlayerSettings playerSettings : gameSettings.getPlayerList()) { - players.add(new Player(playerSettings)); + players.add(new Player(playerSettings, gameSettings)); } activePlayer = 0; @@ -52,7 +52,7 @@ public class RoundState implements IRoundState { public void nextPlayer() { activePlayer = (activePlayer + 1) % players.size(); } - + @Override public void setActivePlayerNumber(int i) { int j = i % players.size(); |