Add GameSettings with the initial meld threshold

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@251 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-18 16:02:23 +02:00
parent 0b252810c9
commit 5169f31af0
7 changed files with 77 additions and 10 deletions

View file

@ -18,6 +18,8 @@ public class MockRoundState implements IRoundState {
public int activePlayer; public int activePlayer;
/** */ /** */
public StoneHeap gameHeap; public StoneHeap gameHeap;
/** */
public GameSettings gameSettings;
/** */ /** */
public MockRoundState() { public MockRoundState() {
@ -29,6 +31,7 @@ public class MockRoundState implements IRoundState {
players.add(new MockPlayer("Player 4", Color.BLACK)); players.add(new MockPlayer("Player 4", Color.BLACK));
activePlayer = 0; activePlayer = 0;
gameHeap = new StoneHeap(); gameHeap = new StoneHeap();
gameSettings = new GameSettings();
} }
@Override @Override
@ -66,4 +69,9 @@ public class MockRoundState implements IRoundState {
public void setTable(ITable table) { public void setTable(ITable table) {
setTable = table; setTable = table;
} }
@Override
public GameSettings getGameSettings() {
return gameSettings;
}
} }

View file

@ -3,6 +3,7 @@ package jrummikub;
import javax.swing.UIManager; import javax.swing.UIManager;
import jrummikub.control.GameControl; import jrummikub.control.GameControl;
import jrummikub.model.GameSettings;
import jrummikub.view.impl.View; import jrummikub.view.impl.View;
/** /**
@ -24,9 +25,10 @@ public class JRummikub {
} catch (Exception e) { } catch (Exception e) {
} }
GameSettings gameSettings = new GameSettings();
View view = new View(); View view = new View();
GameControl gameControl = new GameControl(view); GameControl gameControl = new GameControl(gameSettings, view);
gameControl.startGame(); gameControl.startGame();
} }

View file

@ -1,5 +1,6 @@
package jrummikub.control; package jrummikub.control;
import jrummikub.model.GameSettings;
import jrummikub.model.RoundState; import jrummikub.model.RoundState;
import jrummikub.util.IListener; import jrummikub.util.IListener;
import jrummikub.view.IView; import jrummikub.view.IView;
@ -8,16 +9,20 @@ import jrummikub.view.IView;
* Controls a Game, at some point including all Rounds, starts new Rounds * Controls a Game, at some point including all Rounds, starts new Rounds
*/ */
public class GameControl { public class GameControl {
private GameSettings gameSettings;
private IView view; private IView view;
private RoundControl roundControl; private RoundControl roundControl;
/** /**
* Constructor * Constructor
* *
* @param gameSettings
* the game settings
* @param view * @param view
* the view * the view
*/ */
public GameControl(IView view) { public GameControl(GameSettings gameSettings, IView view) {
this.gameSettings = gameSettings;
this.view = view; this.view = view;
view.getNewGameEvent().add(new IListener() { view.getNewGameEvent().add(new IListener() {
@ -46,7 +51,7 @@ public class GameControl {
return; return;
} }
RoundState gameState = new RoundState(); RoundState gameState = new RoundState(gameSettings);
roundControl = new RoundControl(gameState, view); roundControl = new RoundControl(gameState, view);
roundControl.getEndRoundEvent().add(new IListener() { roundControl.getEndRoundEvent().add(new IListener() {

View file

@ -0,0 +1,33 @@
package jrummikub.model;
/**
* The overall game settings
*/
public class GameSettings {
private int initialMeldThreshold;
/**
* Creates new GameSettings with default values
*/
public GameSettings() {
initialMeldThreshold = 30;
}
/**
* Sets the initial meld threshold
*
* @param value the value to set
*/
public void setInitialMeldThreshold(int value) {
initialMeldThreshold = value;
}
/**
* Returns the initial meld threshold
*
* @return the threshold
*/
public int getInitialMeldThreshold() {
return initialMeldThreshold;
}
}

View file

@ -5,6 +5,13 @@ package jrummikub.model;
*/ */
public interface IRoundState { public interface IRoundState {
/**
* Get the current {@link GameSettings}
*
* @return The game settings
*/
public GameSettings getGameSettings();
/** /**
* Get the current {@link Table} * Get the current {@link Table}
* *
@ -16,7 +23,7 @@ public interface IRoundState {
* Sets the current {@link Table} * Sets the current {@link Table}
* *
* @param table * @param table
* The new Table * The new Table
*/ */
public void setTable(ITable table); public void setTable(ITable table);
@ -48,7 +55,7 @@ public interface IRoundState {
* Returns the player that would be the active player after i turns * Returns the player that would be the active player after i turns
* *
* @param i * @param i
* number of turns * number of turns
* @return player active after i turns * @return player active after i turns
*/ */
public IPlayer getNthNextPlayer(int i); public IPlayer getNthNextPlayer(int i);

View file

@ -4,17 +4,24 @@ 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 RoundState */
public class RoundState implements IRoundState { public class RoundState implements IRoundState {
private GameSettings gameSettings;
private ITable table; private ITable table;
private List<Player> players; private List<Player> players;
private int activePlayer; private int activePlayer;
private StoneHeap gameHeap; private StoneHeap gameHeap;
/** /**
* Create a new GameState with an empty table and (currently) 4 new players. * Create a new RoundState with an empty table
*
* @param gameSettings
* the game settings
*/ */
public RoundState() { public RoundState(GameSettings gameSettings) {
this.gameSettings = gameSettings;
table = new Table(); table = new Table();
players = new ArrayList<Player>(); players = new ArrayList<Player>();
players.add(new Player("Ida", Color.RED)); players.add(new Player("Ida", Color.RED));
@ -59,4 +66,9 @@ public class RoundState implements IRoundState {
public StoneHeap getGameHeap() { public StoneHeap getGameHeap() {
return gameHeap; return gameHeap;
} }
@Override
public GameSettings getGameSettings() {
return gameSettings;
}
} }

View file

@ -15,7 +15,7 @@ public class RoundStateTest {
/** */ /** */
@Before @Before
public void createGame() { public void createGame() {
testGame = new RoundState(); testGame = new RoundState(new GameSettings());
} }
/** */ /** */