Calculate points on hand
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@264 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
92d1109954
commit
4a98975b0d
10 changed files with 88 additions and 15 deletions
|
@ -76,4 +76,10 @@ public class MockHand implements IHand {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getStonePoints() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ public class MockPlayer implements IPlayer {
|
||||||
* @param playerSettings
|
* @param playerSettings
|
||||||
* the player settings
|
* the player settings
|
||||||
*/
|
*/
|
||||||
public MockPlayer(PlayerSettings playerSettings) {
|
public MockPlayer(PlayerSettings playerSettings, GameSettings gameSettings) {
|
||||||
hand = new Hand();
|
hand = new Hand(gameSettings);
|
||||||
this.playerSettings = playerSettings;
|
this.playerSettings = playerSettings;
|
||||||
laidOut = false;
|
laidOut = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,14 @@ public class MockRoundState implements IRoundState {
|
||||||
public MockRoundState() {
|
public MockRoundState() {
|
||||||
table = new MockTable();
|
table = new MockTable();
|
||||||
players = new ArrayList<MockPlayer>();
|
players = new ArrayList<MockPlayer>();
|
||||||
players.add(new MockPlayer(new PlayerSettings("Player 1", Color.RED)));
|
players.add(new MockPlayer(new PlayerSettings("Player 1", Color.RED),
|
||||||
players.add(new MockPlayer(new PlayerSettings("Player 2", Color.YELLOW)));
|
gameSettings));
|
||||||
players.add(new MockPlayer(new PlayerSettings("Player 3", Color.GREEN)));
|
players.add(new MockPlayer(
|
||||||
players.add(new MockPlayer(new PlayerSettings("Player 4", Color.BLACK)));
|
new PlayerSettings("Player 2", Color.YELLOW), gameSettings));
|
||||||
|
players.add(new MockPlayer(new PlayerSettings("Player 3", Color.GREEN),
|
||||||
|
gameSettings));
|
||||||
|
players.add(new MockPlayer(new PlayerSettings("Player 4", Color.BLACK),
|
||||||
|
gameSettings));
|
||||||
activePlayer = 0;
|
activePlayer = 0;
|
||||||
gameHeap = new StoneHeap();
|
gameHeap = new StoneHeap();
|
||||||
gameSettings = new GameSettings();
|
gameSettings = new GameSettings();
|
||||||
|
|
|
@ -10,12 +10,14 @@ public class GameSettings {
|
||||||
private List<PlayerSettings> players = new ArrayList<PlayerSettings>();
|
private List<PlayerSettings> players = new ArrayList<PlayerSettings>();
|
||||||
|
|
||||||
private int initialMeldThreshold;
|
private int initialMeldThreshold;
|
||||||
|
private int jokerPoints;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates new GameSettings with default values
|
* Creates new GameSettings with default values
|
||||||
*/
|
*/
|
||||||
public GameSettings() {
|
public GameSettings() {
|
||||||
initialMeldThreshold = 30;
|
initialMeldThreshold = 30;
|
||||||
|
jokerPoints = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,7 +33,7 @@ public class GameSettings {
|
||||||
* Sets the initial meld threshold
|
* Sets the initial meld threshold
|
||||||
*
|
*
|
||||||
* @param value
|
* @param value
|
||||||
* the value to set
|
* the value to set
|
||||||
*/
|
*/
|
||||||
public void setInitialMeldThreshold(int value) {
|
public void setInitialMeldThreshold(int value) {
|
||||||
initialMeldThreshold = value;
|
initialMeldThreshold = value;
|
||||||
|
@ -45,4 +47,23 @@ public class GameSettings {
|
||||||
public int getInitialMeldThreshold() {
|
public int getInitialMeldThreshold() {
|
||||||
return initialMeldThreshold;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,12 @@ public class Hand extends StoneTray<Stone> implements IHand {
|
||||||
*/
|
*/
|
||||||
public final static int WIDTH = 14;
|
public final static int WIDTH = 14;
|
||||||
|
|
||||||
|
private GameSettings settings;
|
||||||
|
|
||||||
|
public Hand(GameSettings settings) {
|
||||||
|
this.settings = settings;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getFreeRowSpace(int row) {
|
public int getFreeRowSpace(int row) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,15 @@ public interface IHand extends IStoneTray<Stone> {
|
||||||
* Gets the amount of free space in a hand row
|
* Gets the amount of free space in a hand row
|
||||||
*
|
*
|
||||||
* @param row
|
* @param row
|
||||||
* the row number
|
* the row number
|
||||||
* @return the number of stones that can fit into the row
|
* @return the number of stones that can fit into the row
|
||||||
*/
|
*/
|
||||||
int getFreeRowSpace(int row);
|
int getFreeRowSpace(int row);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the accumulated number of points of stones in the hand
|
||||||
|
*
|
||||||
|
* @return points
|
||||||
|
*/
|
||||||
|
int getStonePoints();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,10 @@ public class Player implements IPlayer {
|
||||||
* @param settings
|
* @param settings
|
||||||
* the player settings
|
* the player settings
|
||||||
*/
|
*/
|
||||||
public Player(PlayerSettings settings) {
|
public Player(PlayerSettings settings, GameSettings gameSettings) {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
|
||||||
hand = new Hand();
|
hand = new Hand(gameSettings);
|
||||||
laidOut = false;
|
laidOut = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public class RoundState implements IRoundState {
|
||||||
players = new ArrayList<Player>();
|
players = new ArrayList<Player>();
|
||||||
|
|
||||||
for (PlayerSettings playerSettings : gameSettings.getPlayerList()) {
|
for (PlayerSettings playerSettings : gameSettings.getPlayerList()) {
|
||||||
players.add(new Player(playerSettings));
|
players.add(new Player(playerSettings, gameSettings));
|
||||||
}
|
}
|
||||||
|
|
||||||
activePlayer = 0;
|
activePlayer = 0;
|
||||||
|
|
|
@ -591,7 +591,7 @@ public class RoundControlTest {
|
||||||
|
|
||||||
view.tablePanel.clickEvent.emit(new Position(0, 0));
|
view.tablePanel.clickEvent.emit(new Position(0, 0));
|
||||||
|
|
||||||
testRoundState.players.get(0).hand = new Hand();
|
testRoundState.players.get(0).hand = new Hand(gameSettings);
|
||||||
resetTurnStart();
|
resetTurnStart();
|
||||||
view.playerPanel.endTurnEvent.emit();
|
view.playerPanel.endTurnEvent.emit();
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class HandTest {
|
||||||
/** */
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
hand = new Hand();
|
hand = new Hand(new GameSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
|
@ -111,4 +111,19 @@ public class HandTest {
|
||||||
assertEquals(new Position(13, 1), hand.getPosition(newStone));
|
assertEquals(new Position(13, 1), hand.getPosition(newStone));
|
||||||
assertEquals(new Position(0, 2), hand.getPosition(rowStones.get(13)));
|
assertEquals(new Position(0, 2), hand.getPosition(rowStones.get(13)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** */
|
||||||
|
@Test
|
||||||
|
public void testCountPoints() {
|
||||||
|
|
||||||
|
Stone stone1 = new Stone(2, BLUE);
|
||||||
|
Stone stone2 = new Stone(4, BLUE);
|
||||||
|
Stone stone3 = new Stone(RED);
|
||||||
|
|
||||||
|
hand.drop(stone1, new Position(0, 0));
|
||||||
|
hand.drop(stone2, new Position(0, 0));
|
||||||
|
hand.drop(stone3, new Position(0, 0));
|
||||||
|
|
||||||
|
assertEquals(56, hand.getStonePoints());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue