From b3c903a2ad86aa803fe9bcf83aea947c452241b5 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Wed, 18 May 2011 15:25:26 +0200 Subject: GameState ist jetzt RoundState git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@249 72836036-5685-4462-b002-a69064685172 --- mock/jrummikub/model/MockGameState.java | 69 ---------------------------- mock/jrummikub/model/MockRoundState.java | 69 ++++++++++++++++++++++++++++ src/jrummikub/control/GameControl.java | 4 +- src/jrummikub/control/RoundControl.java | 6 +-- src/jrummikub/model/GameState.java | 62 ------------------------- src/jrummikub/model/IGameState.java | 56 ---------------------- src/jrummikub/model/IRoundState.java | 56 ++++++++++++++++++++++ src/jrummikub/model/RoundState.java | 62 +++++++++++++++++++++++++ test/jrummikub/control/RoundControlTest.java | 6 +-- test/jrummikub/model/GameStateTest.java | 35 -------------- test/jrummikub/model/RoundStateTest.java | 35 ++++++++++++++ 11 files changed, 230 insertions(+), 230 deletions(-) delete mode 100644 mock/jrummikub/model/MockGameState.java create mode 100644 mock/jrummikub/model/MockRoundState.java delete mode 100644 src/jrummikub/model/GameState.java delete mode 100644 src/jrummikub/model/IGameState.java create mode 100644 src/jrummikub/model/IRoundState.java create mode 100644 src/jrummikub/model/RoundState.java delete mode 100644 test/jrummikub/model/GameStateTest.java create mode 100644 test/jrummikub/model/RoundStateTest.java diff --git a/mock/jrummikub/model/MockGameState.java b/mock/jrummikub/model/MockGameState.java deleted file mode 100644 index 53e332e..0000000 --- a/mock/jrummikub/model/MockGameState.java +++ /dev/null @@ -1,69 +0,0 @@ -package jrummikub.model; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; - -/** - * Mock class for {@link GameState} - */ -public class MockGameState implements IGameState { - /** */ - public MockTable table; - /** */ - public ITable setTable; - /** */ - public List players; - /** */ - public int activePlayer; - /** */ - public StoneHeap gameHeap; - - /** */ - public MockGameState() { - table = new MockTable(); - players = new ArrayList(); - players.add(new MockPlayer("Player 1", Color.RED)); - players.add(new MockPlayer("Player 2", Color.YELLOW)); - players.add(new MockPlayer("Player 3", Color.GREEN)); - players.add(new MockPlayer("Player 4", Color.BLACK)); - activePlayer = 0; - gameHeap = new StoneHeap(); - } - - @Override - public ITable getTable() { - return table; - } - - @Override - public int getPlayerCount() { - return players.size(); - } - - /** Changes the activePlayer to the next {@link Player} in the list */ - @Override - public void nextPlayer() { - activePlayer = (activePlayer + 1) % players.size(); - } - - @Override - public IPlayer getActivePlayer() { - return players.get(activePlayer); - } - - @Override - public StoneHeap getGameHeap() { - return gameHeap; - } - - @Override - public IPlayer getNthNextPlayer(int i) { - return players.get((activePlayer + i) % players.size()); - } - - @Override - public void setTable(ITable table) { - setTable = table; - } -} diff --git a/mock/jrummikub/model/MockRoundState.java b/mock/jrummikub/model/MockRoundState.java new file mode 100644 index 0000000..9346783 --- /dev/null +++ b/mock/jrummikub/model/MockRoundState.java @@ -0,0 +1,69 @@ +package jrummikub.model; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +/** + * Mock class for {@link RoundState} + */ +public class MockRoundState implements IRoundState { + /** */ + public MockTable table; + /** */ + public ITable setTable; + /** */ + public List players; + /** */ + public int activePlayer; + /** */ + public StoneHeap gameHeap; + + /** */ + public MockRoundState() { + table = new MockTable(); + players = new ArrayList(); + players.add(new MockPlayer("Player 1", Color.RED)); + players.add(new MockPlayer("Player 2", Color.YELLOW)); + players.add(new MockPlayer("Player 3", Color.GREEN)); + players.add(new MockPlayer("Player 4", Color.BLACK)); + activePlayer = 0; + gameHeap = new StoneHeap(); + } + + @Override + public ITable getTable() { + return table; + } + + @Override + public int getPlayerCount() { + return players.size(); + } + + /** Changes the activePlayer to the next {@link Player} in the list */ + @Override + public void nextPlayer() { + activePlayer = (activePlayer + 1) % players.size(); + } + + @Override + public IPlayer getActivePlayer() { + return players.get(activePlayer); + } + + @Override + public StoneHeap getGameHeap() { + return gameHeap; + } + + @Override + public IPlayer getNthNextPlayer(int i) { + return players.get((activePlayer + i) % players.size()); + } + + @Override + public void setTable(ITable table) { + setTable = table; + } +} diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java index ae50b3c..14e5adc 100644 --- a/src/jrummikub/control/GameControl.java +++ b/src/jrummikub/control/GameControl.java @@ -1,6 +1,6 @@ package jrummikub.control; -import jrummikub.model.GameState; +import jrummikub.model.RoundState; import jrummikub.util.IListener; import jrummikub.view.IView; @@ -46,7 +46,7 @@ public class GameControl { return; } - GameState gameState = new GameState(); + RoundState gameState = new RoundState(); roundControl = new RoundControl(gameState, view); roundControl.getEndRoundEvent().add(new IListener() { diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index c46d402..07adb99 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -6,7 +6,7 @@ import java.util.List; import java.util.Set; import jrummikub.model.Hand; -import jrummikub.model.IGameState; +import jrummikub.model.IRoundState; import jrummikub.model.IHand; import jrummikub.model.ITable; import jrummikub.model.Position; @@ -23,7 +23,7 @@ import jrummikub.view.IView; * Controller that manages a single round of rummikub */ public class RoundControl { - private IGameState gameState; + private IRoundState gameState; private IView view; private ITable clonedTable; private Event endRoundEvent = new Event(); @@ -37,7 +37,7 @@ public class RoundControl { * @param view * view used for user interaction */ - public RoundControl(IGameState gameState, IView view) { + public RoundControl(IRoundState gameState, IView view) { this.gameState = gameState; this.view = view; } diff --git a/src/jrummikub/model/GameState.java b/src/jrummikub/model/GameState.java deleted file mode 100644 index 5861a32..0000000 --- a/src/jrummikub/model/GameState.java +++ /dev/null @@ -1,62 +0,0 @@ -package jrummikub.model; - -import java.awt.Color; -import java.util.ArrayList; -import java.util.List; - -/** Class managing the overall and momentary GameState */ -public class GameState implements IGameState { - private ITable table; - private List players; - private int activePlayer; - private StoneHeap gameHeap; - - /** - * Create a new GameState with an empty table and (currently) 4 new players. - */ - public GameState() { - table = new Table(); - players = new ArrayList(); - players.add(new Player("Ida", Color.RED)); - players.add(new Player("Matthias", Color.YELLOW)); - players.add(new Player("Jannis", Color.GREEN)); - players.add(new Player("Bennet", Color.BLACK)); - activePlayer = 0; - gameHeap = new StoneHeap(); - } - - @Override - public ITable getTable() { - return table; - } - - @Override - public void setTable(ITable table) { - this.table = table; - } - - @Override - public int getPlayerCount() { - return players.size(); - } - - @Override - public void nextPlayer() { - activePlayer = (activePlayer + 1) % players.size(); - } - - @Override - public IPlayer getNthNextPlayer(int i) { - return players.get((activePlayer + i) % players.size()); - } - - @Override - public IPlayer getActivePlayer() { - return players.get(activePlayer); - } - - @Override - public StoneHeap getGameHeap() { - return gameHeap; - } -} diff --git a/src/jrummikub/model/IGameState.java b/src/jrummikub/model/IGameState.java deleted file mode 100644 index ebc31c5..0000000 --- a/src/jrummikub/model/IGameState.java +++ /dev/null @@ -1,56 +0,0 @@ -package jrummikub.model; - -/** - * Interface for {@link GameState} model - */ -public interface IGameState { - - /** - * Get the current {@link Table} - * - * @return The current Table - */ - public ITable getTable(); - - /** - * Sets the current {@link Table} - * - * @param table - * The new Table - */ - public void setTable(ITable table); - - /** - * Returns the number of players - * - * @return number of players - */ - public int getPlayerCount(); - - /** Changes the activePlayer to the next {@link Player} in the list */ - public void nextPlayer(); - - /** - * Returns the currently active player - * - * @return currently active player - */ - public IPlayer getActivePlayer(); - - /** - * Returns the heap of stones to draw from - * - * @return heap of stones - */ - public StoneHeap getGameHeap(); - - /** - * Returns the player that would be the active player after i turns - * - * @param i - * number of turns - * @return player active after i turns - */ - public IPlayer getNthNextPlayer(int i); - -} \ No newline at end of file diff --git a/src/jrummikub/model/IRoundState.java b/src/jrummikub/model/IRoundState.java new file mode 100644 index 0000000..cb6cd73 --- /dev/null +++ b/src/jrummikub/model/IRoundState.java @@ -0,0 +1,56 @@ +package jrummikub.model; + +/** + * Interface for {@link RoundState} model + */ +public interface IRoundState { + + /** + * Get the current {@link Table} + * + * @return The current Table + */ + public ITable getTable(); + + /** + * Sets the current {@link Table} + * + * @param table + * The new Table + */ + public void setTable(ITable table); + + /** + * Returns the number of players + * + * @return number of players + */ + public int getPlayerCount(); + + /** Changes the activePlayer to the next {@link Player} in the list */ + public void nextPlayer(); + + /** + * Returns the currently active player + * + * @return currently active player + */ + public IPlayer getActivePlayer(); + + /** + * Returns the heap of stones to draw from + * + * @return heap of stones + */ + public StoneHeap getGameHeap(); + + /** + * Returns the player that would be the active player after i turns + * + * @param i + * number of turns + * @return player active after i turns + */ + public IPlayer getNthNextPlayer(int i); + +} \ No newline at end of file diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java new file mode 100644 index 0000000..82d93b0 --- /dev/null +++ b/src/jrummikub/model/RoundState.java @@ -0,0 +1,62 @@ +package jrummikub.model; + +import java.awt.Color; +import java.util.ArrayList; +import java.util.List; + +/** Class managing the overall and momentary GameState */ +public class RoundState implements IRoundState { + private ITable table; + private List players; + private int activePlayer; + private StoneHeap gameHeap; + + /** + * Create a new GameState with an empty table and (currently) 4 new players. + */ + public RoundState() { + table = new Table(); + players = new ArrayList(); + players.add(new Player("Ida", Color.RED)); + players.add(new Player("Matthias", Color.YELLOW)); + players.add(new Player("Jannis", Color.GREEN)); + players.add(new Player("Bennet", Color.BLACK)); + activePlayer = 0; + gameHeap = new StoneHeap(); + } + + @Override + public ITable getTable() { + return table; + } + + @Override + public void setTable(ITable table) { + this.table = table; + } + + @Override + public int getPlayerCount() { + return players.size(); + } + + @Override + public void nextPlayer() { + activePlayer = (activePlayer + 1) % players.size(); + } + + @Override + public IPlayer getNthNextPlayer(int i) { + return players.get((activePlayer + i) % players.size()); + } + + @Override + public IPlayer getActivePlayer() { + return players.get(activePlayer); + } + + @Override + public StoneHeap getGameHeap() { + return gameHeap; + } +} diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java index 1be11e4..4cfb03f 100644 --- a/test/jrummikub/control/RoundControlTest.java +++ b/test/jrummikub/control/RoundControlTest.java @@ -20,7 +20,7 @@ import java.util.Set; import jrummikub.model.Hand; import jrummikub.model.IHand; import jrummikub.model.ITable; -import jrummikub.model.MockGameState; +import jrummikub.model.MockRoundState; import jrummikub.model.MockTable; import jrummikub.model.Position; import jrummikub.model.Stone; @@ -37,7 +37,7 @@ import org.junit.Test; */ public class RoundControlTest { private MockView view; - private MockGameState testGameState; + private MockRoundState testGameState; private RoundControl testRound; private MockTable newTable; @@ -47,7 +47,7 @@ public class RoundControlTest { @Before public void setup() { view = new MockView(); - testGameState = new MockGameState(); + testGameState = new MockRoundState(); testRound = new RoundControl(testGameState, view); Stone stone = testGameState.getGameHeap().drawStone(); testGameState.table.drop(new StoneSet(stone), new Position(5, 0)); diff --git a/test/jrummikub/model/GameStateTest.java b/test/jrummikub/model/GameStateTest.java deleted file mode 100644 index 5a55aef..0000000 --- a/test/jrummikub/model/GameStateTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package jrummikub.model; - -import static org.junit.Assert.*; - -import java.awt.Color; - -import org.junit.Before; -import org.junit.Test; -/** - * Test class for {@link GameState} - */ -public class GameStateTest { - private IGameState testGame; - - /** */ - @Before - public void createGame() { - testGame = new GameState(); - } - - /** */ - @Test - public void nextActiveTest() { - // All there? - assertEquals(4, testGame.getPlayerCount()); - assertSame(Color.red, testGame.getActivePlayer().getColor()); - testGame.nextPlayer(); - assertSame(Color.yellow, testGame.getActivePlayer().getColor()); - testGame.nextPlayer(); - testGame.nextPlayer(); - testGame.nextPlayer(); - assertSame(Color.red, testGame.getActivePlayer().getColor()); - } - -} diff --git a/test/jrummikub/model/RoundStateTest.java b/test/jrummikub/model/RoundStateTest.java new file mode 100644 index 0000000..80b752e --- /dev/null +++ b/test/jrummikub/model/RoundStateTest.java @@ -0,0 +1,35 @@ +package jrummikub.model; + +import static org.junit.Assert.*; + +import java.awt.Color; + +import org.junit.Before; +import org.junit.Test; +/** + * Test class for {@link RoundState} + */ +public class RoundStateTest { + private IRoundState testGame; + + /** */ + @Before + public void createGame() { + testGame = new RoundState(); + } + + /** */ + @Test + public void nextActiveTest() { + // All there? + assertEquals(4, testGame.getPlayerCount()); + assertSame(Color.red, testGame.getActivePlayer().getColor()); + testGame.nextPlayer(); + assertSame(Color.yellow, testGame.getActivePlayer().getColor()); + testGame.nextPlayer(); + testGame.nextPlayer(); + testGame.nextPlayer(); + assertSame(Color.red, testGame.getActivePlayer().getColor()); + } + +} -- cgit v1.2.3