RoundControl: Create players from player settings list from game settings
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@253 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
b5397d5aa7
commit
e76977652d
5 changed files with 54 additions and 22 deletions
|
@ -1,9 +1,12 @@
|
||||||
package jrummikub;
|
package jrummikub;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
import jrummikub.control.GameControl;
|
import jrummikub.control.GameControl;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
|
import jrummikub.model.PlayerSettings;
|
||||||
import jrummikub.view.impl.View;
|
import jrummikub.view.impl.View;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,6 +29,12 @@ public class JRummikub {
|
||||||
}
|
}
|
||||||
|
|
||||||
GameSettings gameSettings = new GameSettings();
|
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();
|
View view = new View();
|
||||||
|
|
||||||
GameControl gameControl = new GameControl(gameSettings, view);
|
GameControl gameControl = new GameControl(gameSettings, view);
|
||||||
|
|
|
@ -51,9 +51,9 @@ public class GameControl {
|
||||||
return;
|
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() {
|
roundControl.getEndRoundEvent().add(new IListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,9 +1,14 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The overall game settings
|
* The overall game settings
|
||||||
*/
|
*/
|
||||||
public class GameSettings {
|
public class GameSettings {
|
||||||
|
private List<PlayerSettings> players = new ArrayList<PlayerSettings>();
|
||||||
|
|
||||||
private int initialMeldThreshold;
|
private int initialMeldThreshold;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,10 +18,20 @@ public class GameSettings {
|
||||||
initialMeldThreshold = 30;
|
initialMeldThreshold = 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
* Sets the initial meld threshold
|
||||||
*
|
*
|
||||||
* @param value the value to set
|
* @param value
|
||||||
|
* the value to set
|
||||||
*/
|
*/
|
||||||
public void setInitialMeldThreshold(int value) {
|
public void setInitialMeldThreshold(int value) {
|
||||||
initialMeldThreshold = value;
|
initialMeldThreshold = value;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
||||||
|
@ -24,10 +23,11 @@ public class RoundState implements IRoundState {
|
||||||
|
|
||||||
table = new Table();
|
table = new Table();
|
||||||
players = new ArrayList<Player>();
|
players = new ArrayList<Player>();
|
||||||
players.add(new Player(new PlayerSettings("Ida", Color.RED)));
|
|
||||||
players.add(new Player(new PlayerSettings("Matthias", Color.YELLOW)));
|
for (PlayerSettings playerSettings : gameSettings.getPlayerList()) {
|
||||||
players.add(new Player(new PlayerSettings("Jannis", Color.GREEN)));
|
players.add(new Player(playerSettings));
|
||||||
players.add(new Player(new PlayerSettings("Bennet", Color.BLACK)));
|
}
|
||||||
|
|
||||||
activePlayer = 0;
|
activePlayer = 0;
|
||||||
gameHeap = new StoneHeap();
|
gameHeap = new StoneHeap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,30 +6,38 @@ import java.awt.Color;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for {@link RoundState}
|
* Test class for {@link RoundState}
|
||||||
*/
|
*/
|
||||||
public class RoundStateTest {
|
public class RoundStateTest {
|
||||||
private IRoundState testGame;
|
private GameSettings settings = new GameSettings();
|
||||||
|
private IRoundState testRound;
|
||||||
|
|
||||||
/** */
|
/** */
|
||||||
@Before
|
@Before
|
||||||
public void createGame() {
|
public void createRound() {
|
||||||
testGame = new RoundState(new GameSettings());
|
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
|
@Test
|
||||||
public void nextActiveTest() {
|
public void nextActiveTest() {
|
||||||
// All there?
|
// All there?
|
||||||
assertEquals(4, testGame.getPlayerCount());
|
assertEquals(settings.getPlayerList().size(), testRound.getPlayerCount());
|
||||||
assertSame(Color.red, testGame.getActivePlayer().getPlayerSettings().getColor());
|
assertSame(Color.RED, testRound.getActivePlayer().getPlayerSettings()
|
||||||
testGame.nextPlayer();
|
.getColor());
|
||||||
assertSame(Color.yellow, testGame.getActivePlayer().getPlayerSettings().getColor());
|
testRound.nextPlayer();
|
||||||
testGame.nextPlayer();
|
assertSame(Color.YELLOW, testRound.getActivePlayer().getPlayerSettings()
|
||||||
testGame.nextPlayer();
|
.getColor());
|
||||||
testGame.nextPlayer();
|
testRound.nextPlayer();
|
||||||
assertSame(Color.red, testGame.getActivePlayer().getPlayerSettings().getColor());
|
testRound.nextPlayer();
|
||||||
|
assertSame(Color.RED, testRound.getActivePlayer().getPlayerSettings()
|
||||||
|
.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue