summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-05-24 01:51:54 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-05-24 01:51:54 +0200
commit92d110995488380778bd378f4297032a325dc385 (patch)
tree38bc26c6228a588b160bc0b053768044791dcaa4 /src
parentd9a0b0e37dbdde6d60fa4ee41c2a100547e7824b (diff)
downloadJRummikub-92d110995488380778bd378f4297032a325dc385.tar
JRummikub-92d110995488380778bd378f4297032a325dc385.zip
Select a random player for the first round
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@263 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/GameControl.java8
-rw-r--r--src/jrummikub/model/GameState.java24
-rw-r--r--src/jrummikub/model/IRoundState.java14
-rw-r--r--src/jrummikub/model/RoundState.java9
4 files changed, 52 insertions, 3 deletions
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java
index 1d93c63..ac47e2f 100644
--- a/src/jrummikub/control/GameControl.java
+++ b/src/jrummikub/control/GameControl.java
@@ -1,6 +1,7 @@
package jrummikub.control;
import jrummikub.model.GameSettings;
+import jrummikub.model.GameState;
import jrummikub.model.IRoundState;
import jrummikub.model.RoundState;
import jrummikub.util.IListener;
@@ -13,6 +14,7 @@ public class GameControl {
private GameSettings gameSettings;
private IView view;
private RoundControl roundControl;
+ private GameState gameState;
/**
* Constructor
@@ -25,6 +27,9 @@ public class GameControl {
public GameControl(GameSettings gameSettings, IView view) {
this.gameSettings = gameSettings;
this.view = view;
+
+ gameState = new GameState();
+ gameState.setFirstRoundFirstPlayer((int)(Math.random() * gameSettings.getPlayerList().size()));
view.getNewGameEvent().add(new IListener() {
@Override
@@ -54,6 +59,9 @@ public class GameControl {
IRoundState roundState = new RoundState(gameSettings);
+ // TODO: add number of already played rounds
+ roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer());
+
roundControl = new RoundControl(roundState, view);
roundControl.getEndRoundEvent().add(new IListener() {
diff --git a/src/jrummikub/model/GameState.java b/src/jrummikub/model/GameState.java
new file mode 100644
index 0000000..4bb55bc
--- /dev/null
+++ b/src/jrummikub/model/GameState.java
@@ -0,0 +1,24 @@
+package jrummikub.model;
+
+/**
+ * Class that stores information for a game of multiple rounds
+ */
+public class GameState {
+ private int firstRoundFirstPlayer;
+
+ /**
+ * Gets the number of the first player of the first round
+ * @return the number of the first player of the first round
+ */
+ public int getFirstRoundFirstPlayer() {
+ return firstRoundFirstPlayer;
+ }
+
+ /**
+ * Sets the number of the first player of the first round
+ * @param firstRoundFirstPlayer the number of the first player of the first round
+ */
+ public void setFirstRoundFirstPlayer(int firstRoundFirstPlayer) {
+ this.firstRoundFirstPlayer = firstRoundFirstPlayer;
+ }
+}
diff --git a/src/jrummikub/model/IRoundState.java b/src/jrummikub/model/IRoundState.java
index dea225b..4dbcd9a 100644
--- a/src/jrummikub/model/IRoundState.java
+++ b/src/jrummikub/model/IRoundState.java
@@ -64,8 +64,7 @@ public interface IRoundState {
* Sets the player that will make the last turn before the round ends when
* the heap is empty
*
- * @param lastPlayer
- * the last player
+ * @return the last player
*/
public abstract IPlayer getLastPlayer();
@@ -73,8 +72,17 @@ public interface IRoundState {
* Gets the player that will make the last turn before the round ends when
* the heap is empty
*
- * @return lastPlayer the last player
+ * @param lastPlayer
+ * the last player
*/
public abstract void setLastPlayer(IPlayer lastPlayer);
+ /**
+ * Makes the player with number i the active player
+ *
+ * @param i
+ * number of the player to make active
+ */
+ public void setActivePlayerNumber(int i);
+
} \ No newline at end of file
diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java
index 0bda737..076fd00 100644
--- a/src/jrummikub/model/RoundState.java
+++ b/src/jrummikub/model/RoundState.java
@@ -52,6 +52,15 @@ public class RoundState implements IRoundState {
public void nextPlayer() {
activePlayer = (activePlayer + 1) % players.size();
}
+
+ @Override
+ public void setActivePlayerNumber(int i) {
+ int j = i % players.size();
+ if (j < 0) {
+ j += players.size();
+ }
+ activePlayer = j;
+ }
@Override
public IPlayer getNthNextPlayer(int i) {