From 699a0b0a2933237039b9b6ac545cc05a34644399 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Sun, 29 May 2011 18:50:54 +0200 Subject: Deal the correct number of jokers aka funny joker action git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@303 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/model/RoundState.java | 2 +- src/jrummikub/model/StoneHeap.java | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java index 65bc120..9f1f7be 100644 --- a/src/jrummikub/model/RoundState.java +++ b/src/jrummikub/model/RoundState.java @@ -33,7 +33,7 @@ public class RoundState implements IRoundState { turnNumber = 1-gameSettings.getPlayerList().size(); activePlayer = 0; - gameHeap = new StoneHeap(); + gameHeap = new StoneHeap(gameSettings); } @Override diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java index 048f6e7..4ccb427 100644 --- a/src/jrummikub/model/StoneHeap.java +++ b/src/jrummikub/model/StoneHeap.java @@ -1,6 +1,7 @@ package jrummikub.model; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.EnumSet; import java.util.List; @@ -14,9 +15,9 @@ import java.util.Random; public class StoneHeap { List heap; private Random generator = new Random(); - + /** Creates 106 Stones according to standard rules */ - public StoneHeap() { + public StoneHeap(GameSettings gameSettings) { heap = new ArrayList(); for (int i = 1; i <= 13; i++) { for (int j = 0; j < 2; j++) { @@ -26,8 +27,22 @@ public class StoneHeap { } } // Joker - heap.add(new Stone(StoneColor.BLACK)); - heap.add(new Stone(StoneColor.RED)); + + ArrayList jokerColors = new ArrayList(Arrays.asList(StoneColor.values())); + + StoneColor temp = jokerColors.get(0); + jokerColors.set(0, jokerColors.get(2)); + jokerColors.set(2, temp); + + int jokersLeft = gameSettings.getJokerNumber(); + done : while(true) { + for (StoneColor c : jokerColors) { + if (jokersLeft == 0) + break done; + heap.add(new Stone(c)); + jokersLeft--; + } + } } /** -- cgit v1.2.3