Nochmal: GameState fertig und getestet, diesmal richtig
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@93 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
2f4f2f79ae
commit
e7613bfd93
3 changed files with 28 additions and 6 deletions
|
@ -1,26 +1,36 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/** Class managing the overall and momentary GameState */
|
/** Class managing the overall and momentary GameState */
|
||||||
public class GameState {
|
public class GameState {
|
||||||
private Table table;
|
Table table;
|
||||||
private List<Player> players;
|
List<Player> players;
|
||||||
private int activePlayer;
|
int activePlayer;
|
||||||
private StoneHeap gameHeap;
|
private StoneHeap gameHeap;
|
||||||
|
|
||||||
public GameState() {
|
public GameState() {
|
||||||
this.players=new ArrayList<Player>();
|
players = new ArrayList<Player>();
|
||||||
|
players.add(new Player(Color.red));
|
||||||
|
players.add(new Player(Color.yellow));
|
||||||
|
players.add(new Player(Color.green));
|
||||||
|
players.add(new Player(Color.black));
|
||||||
|
activePlayer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Changes the activePlayer to the next {@link Player} in the list */
|
/** Changes the activePlayer to the next {@link Player} in the list */
|
||||||
public void nextPlayer() {
|
public void nextPlayer() {
|
||||||
|
activePlayer = (activePlayer + 1) % 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player activePlayer() {
|
public Player activePlayer() {
|
||||||
|
return players.get(activePlayer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StoneHeap getGameHeap() {
|
||||||
|
return gameHeap;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,22 @@ import java.awt.Color;
|
||||||
|
|
||||||
/** Class managing player data. No methods in release 1 */
|
/** Class managing player data. No methods in release 1 */
|
||||||
public class Player {
|
public class Player {
|
||||||
|
public Player(Color color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
private Hand hand;
|
private Hand hand;
|
||||||
|
|
||||||
private Color color;
|
private Color color;
|
||||||
|
|
||||||
|
public Hand getHand() {
|
||||||
|
return hand;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
// private String name;
|
// private String name;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ public class GameStateTest {
|
||||||
assertEquals(4, testGame.players.size());
|
assertEquals(4, testGame.players.size());
|
||||||
assertSame(Color.red, testGame.activePlayer().getColor());
|
assertSame(Color.red, testGame.activePlayer().getColor());
|
||||||
testGame.nextPlayer();
|
testGame.nextPlayer();
|
||||||
assertSame(Color.blue, testGame.activePlayer().getColor());
|
assertSame(Color.yellow, testGame.activePlayer().getColor());
|
||||||
testGame.nextPlayer();
|
testGame.nextPlayer();
|
||||||
testGame.nextPlayer();
|
testGame.nextPlayer();
|
||||||
testGame.nextPlayer();
|
testGame.nextPlayer();
|
||||||
|
|
Reference in a new issue