summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/JRummikub.java11
-rw-r--r--src/jrummikub/control/GameControl.java4
-rw-r--r--src/jrummikub/model/GameSettings.java17
-rw-r--r--src/jrummikub/model/RoundState.java10
-rw-r--r--test/jrummikub/model/RoundStateTest.java34
5 files changed, 54 insertions, 22 deletions
diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java
index a1fada3..9c22dc6 100644
--- a/src/jrummikub/JRummikub.java
+++ b/src/jrummikub/JRummikub.java
@@ -1,9 +1,12 @@
package jrummikub;
+import java.awt.Color;
+
import javax.swing.UIManager;
import jrummikub.control.GameControl;
import jrummikub.model.GameSettings;
+import jrummikub.model.PlayerSettings;
import jrummikub.view.impl.View;
/**
@@ -15,7 +18,7 @@ public class JRummikub {
* The main method
*
* @param args
- * command line arguments
+ * command line arguments
*/
public static void main(String[] args) {
String nativeLF = UIManager.getSystemLookAndFeelClassName();
@@ -26,6 +29,12 @@ public class JRummikub {
}
GameSettings gameSettings = new GameSettings();
+ gameSettings.getPlayerList().add(new PlayerSettings("Ida", Color.RED));
+ gameSettings.getPlayerList().add(
+ new PlayerSettings("Matthias", Color.YELLOW));
+ gameSettings.getPlayerList().add(new PlayerSettings("Jannis", Color.GREEN));
+ gameSettings.getPlayerList().add(new PlayerSettings("Bennet", Color.BLACK));
+
View view = new View();
GameControl gameControl = new GameControl(gameSettings, view);
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java
index 195eba3..b5d763a 100644
--- a/src/jrummikub/control/GameControl.java
+++ b/src/jrummikub/control/GameControl.java
@@ -51,9 +51,9 @@ public class GameControl {
return;
}
- RoundState gameState = new RoundState(gameSettings);
+ RoundState roundState = new RoundState(gameSettings);
- roundControl = new RoundControl(gameState, view);
+ roundControl = new RoundControl(roundState, view);
roundControl.getEndRoundEvent().add(new IListener() {
@Override
diff --git a/src/jrummikub/model/GameSettings.java b/src/jrummikub/model/GameSettings.java
index b7177ef..b5079d4 100644
--- a/src/jrummikub/model/GameSettings.java
+++ b/src/jrummikub/model/GameSettings.java
@@ -1,9 +1,14 @@
package jrummikub.model;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* The overall game settings
*/
public class GameSettings {
+ private List<PlayerSettings> players = new ArrayList<PlayerSettings>();
+
private int initialMeldThreshold;
/**
@@ -14,9 +19,19 @@ public class GameSettings {
}
/**
+ * Returns the list containing the settings of all players
+ *
+ * @return the player settings list
+ */
+ public List<PlayerSettings> getPlayerList() {
+ return players;
+ }
+
+ /**
* Sets the initial meld threshold
*
- * @param value the value to set
+ * @param value
+ * the value to set
*/
public void setInitialMeldThreshold(int value) {
initialMeldThreshold = value;
diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java
index b566fdf..56f7904 100644
--- a/src/jrummikub/model/RoundState.java
+++ b/src/jrummikub/model/RoundState.java
@@ -1,6 +1,5 @@
package jrummikub.model;
-import java.awt.Color;
import java.util.ArrayList;
import java.util.List;
@@ -24,10 +23,11 @@ public class RoundState implements IRoundState {
table = new Table();
players = new ArrayList<Player>();
- players.add(new Player(new PlayerSettings("Ida", Color.RED)));
- players.add(new Player(new PlayerSettings("Matthias", Color.YELLOW)));
- players.add(new Player(new PlayerSettings("Jannis", Color.GREEN)));
- players.add(new Player(new PlayerSettings("Bennet", Color.BLACK)));
+
+ for (PlayerSettings playerSettings : gameSettings.getPlayerList()) {
+ players.add(new Player(playerSettings));
+ }
+
activePlayer = 0;
gameHeap = new StoneHeap();
}
diff --git a/test/jrummikub/model/RoundStateTest.java b/test/jrummikub/model/RoundStateTest.java
index de98090..bfbe857 100644
--- a/test/jrummikub/model/RoundStateTest.java
+++ b/test/jrummikub/model/RoundStateTest.java
@@ -6,30 +6,38 @@ import java.awt.Color;
import org.junit.Before;
import org.junit.Test;
-/**
+
+/**
* Test class for {@link RoundState}
*/
public class RoundStateTest {
- private IRoundState testGame;
+ private GameSettings settings = new GameSettings();
+ private IRoundState testRound;
/** */
@Before
- public void createGame() {
- testGame = new RoundState(new GameSettings());
+ public void createRound() {
+ settings.getPlayerList().add(new PlayerSettings("Player 1", Color.RED));
+ settings.getPlayerList().add(new PlayerSettings("Player 2", Color.YELLOW));
+ settings.getPlayerList().add(new PlayerSettings("Player 3", Color.BLUE));
+
+ testRound = new RoundState(settings);
}
/** */
@Test
public void nextActiveTest() {
// All there?
- assertEquals(4, testGame.getPlayerCount());
- assertSame(Color.red, testGame.getActivePlayer().getPlayerSettings().getColor());
- testGame.nextPlayer();
- assertSame(Color.yellow, testGame.getActivePlayer().getPlayerSettings().getColor());
- testGame.nextPlayer();
- testGame.nextPlayer();
- testGame.nextPlayer();
- assertSame(Color.red, testGame.getActivePlayer().getPlayerSettings().getColor());
+ assertEquals(settings.getPlayerList().size(), testRound.getPlayerCount());
+ assertSame(Color.RED, testRound.getActivePlayer().getPlayerSettings()
+ .getColor());
+ testRound.nextPlayer();
+ assertSame(Color.YELLOW, testRound.getActivePlayer().getPlayerSettings()
+ .getColor());
+ testRound.nextPlayer();
+ testRound.nextPlayer();
+ assertSame(Color.RED, testRound.getActivePlayer().getPlayerSettings()
+ .getColor());
}
-
+
}