From 6e9c1b539b412dc08716eb3f88adb53b3021a27b Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Wed, 4 May 2011 19:09:39 +0200 Subject: =?UTF-8?q?Test=20f=C3=BCr=20Austeilen=20geschrieben,=20eine=20Men?= =?UTF-8?q?ge=20getSize=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@116 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/GameControl.java | 34 ---------------------- src/jrummikub/control/RoundControl.java | 42 ++++++++++++++++++++++++++++ src/jrummikub/model/GameState.java | 19 +++++++++---- src/jrummikub/model/IStoneTray.java | 2 ++ src/jrummikub/model/StoneHeap.java | 4 +++ src/jrummikub/model/StoneTray.java | 38 +++++++++++++++---------- test/jrummikub/control/RoundControlTest.java | 24 ++++++++++++++++ test/jrummikub/model/GameStateTest.java | 8 +++--- 8 files changed, 114 insertions(+), 57 deletions(-) delete mode 100644 src/jrummikub/control/GameControl.java create mode 100644 src/jrummikub/control/RoundControl.java create mode 100644 test/jrummikub/control/RoundControlTest.java diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java deleted file mode 100644 index 3b9d4bb..0000000 --- a/src/jrummikub/control/GameControl.java +++ /dev/null @@ -1,34 +0,0 @@ -package jrummikub.control; - -import jrummikub.model.GameState; -import jrummikub.view.IView; - -public class GameControl { - private GameState gameState; - private IView view; - - public GameControl(GameState gameState, IView view) { - this.gameState = gameState; - this.view = view; - } - - private void endOfTurn() { - - } - - private void ruleCheck() { - - } - - private void resetTable() { - - } - - private void preparePlayerTurn() { - - } - - private void dealStone() { - - } -} diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java new file mode 100644 index 0000000..ae834b9 --- /dev/null +++ b/src/jrummikub/control/RoundControl.java @@ -0,0 +1,42 @@ +package jrummikub.control; + +import jrummikub.model.GameState; +import jrummikub.view.IView; + +public class RoundControl { + private GameState gameState; + private IView view; + + public RoundControl(GameState gameState, IView view) { + this.gameState = gameState; + this.view = view; + } + + public void startRound() { + + } + + void deal() { + + } + + private void endOfTurn() { + + } + + private void ruleCheck() { + + } + + private void resetTable() { + + } + + private void preparePlayerTurn() { + + } + + private void dealStone() { + + } +} diff --git a/src/jrummikub/model/GameState.java b/src/jrummikub/model/GameState.java index 23e51b4..84e206f 100644 --- a/src/jrummikub/model/GameState.java +++ b/src/jrummikub/model/GameState.java @@ -6,9 +6,9 @@ import java.util.List; /** Class managing the overall and momentary GameState */ public class GameState { - ITable table; - List players; - int activePlayer; + private ITable table; + private List players; + private int activePlayer; private StoneHeap gameHeap; public GameState() { @@ -19,18 +19,27 @@ public class GameState { players.add(new Player(Color.green)); players.add(new Player(Color.black)); activePlayer = 0; + } public ITable getTable() { return table; } + public int getPlayerCount() { + return players.size(); + } + + public Player getPlayer(int i) { + return players.get(i); + } + /** Changes the activePlayer to the next {@link Player} in the list */ public void nextPlayer() { - activePlayer = (activePlayer + 1) % 4; + activePlayer = (activePlayer + 1) % players.size(); } - public Player activePlayer() { + public Player getActivePlayer() { return players.get(activePlayer); } diff --git a/src/jrummikub/model/IStoneTray.java b/src/jrummikub/model/IStoneTray.java index a9afed3..b40066a 100644 --- a/src/jrummikub/model/IStoneTray.java +++ b/src/jrummikub/model/IStoneTray.java @@ -37,4 +37,6 @@ public interface IStoneTray extends public IStoneTray clone(); + public int getSize(); + } \ No newline at end of file diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java index e74844e..42cb01e 100644 --- a/src/jrummikub/model/StoneHeap.java +++ b/src/jrummikub/model/StoneHeap.java @@ -52,4 +52,8 @@ public class StoneHeap { } return drawnStones; } + + public int getSize() { + return heap.size(); + } } diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index 080786b..d88d60c 100644 --- a/src/jrummikub/model/StoneTray.java +++ b/src/jrummikub/model/StoneTray.java @@ -11,7 +11,7 @@ import jrummikub.util.Pair; * or {@link StoneSet}s. * * @param - * Type of positioned objects (must implement Sizeable) + * Type of positioned objects (must implement Sizeable) */ public class StoneTray implements IStoneTray { protected HashMap objects = new HashMap(); @@ -39,10 +39,12 @@ public class StoneTray implements IStoneTray { if (position.getY() < currentPosition.getY()) { continue; } - if (position.getX() > currentPosition.getX() + currentObject.getWidth()) { + if (position.getX() > currentPosition.getX() + + currentObject.getWidth()) { continue; } - if (position.getY() > currentPosition.getY() + currentObject.getHeight()) { + if (position.getY() > currentPosition.getY() + + currentObject.getHeight()) { continue; } // Position is inside the current object @@ -70,7 +72,8 @@ public class StoneTray implements IStoneTray { .entrySet()) { Position currentPosition = i.getValue(); E currentObject = i.getKey(); - if (!objectsOverlap(object, position, currentObject, currentPosition)) { + if (!objectsOverlap(object, position, currentObject, + currentPosition)) { continue; } // Object would be placed inside the current object @@ -81,16 +84,16 @@ public class StoneTray implements IStoneTray { // Move object to avoid overlap switch (direction) { case TOP: - newPosition = new Position(currentPosition.getX(), position.getY() - - currentObject.getHeight()); + newPosition = new Position(currentPosition.getX(), + position.getY() - currentObject.getHeight()); break; case BOTTOM: - newPosition = new Position(currentPosition.getX(), position.getY() - + object.getHeight()); + newPosition = new Position(currentPosition.getX(), + position.getY() + object.getHeight()); break; case LEFT: - newPosition = new Position(position.getX() - currentObject.getWidth(), - currentPosition.getY()); + newPosition = new Position(position.getX() + - currentObject.getWidth(), currentPosition.getY()); break; case RIGHT: newPosition = new Position(position.getX() + object.getWidth(), @@ -153,13 +156,15 @@ public class StoneTray implements IStoneTray { float blockingRight = blocking.getValue().getX() + blocking.getKey().getWidth(); float overlapRight = Math.min(objectRight, blockingRight); - float overlapLeft = Math.max(position.getX(), blocking.getValue().getX()); + float overlapLeft = Math.max(position.getX(), blocking.getValue() + .getX()); float overlapX = overlapRight - overlapLeft; float objectBottom = position.getY() + object.getHeight(); float blockingBottom = blocking.getValue().getY() + blocking.getKey().getHeight(); float overlapBottom = Math.min(objectBottom, blockingBottom); - float overlapTop = Math.max(position.getY(), blocking.getValue().getY()); + float overlapTop = Math + .max(position.getY(), blocking.getValue().getY()); float overlapY = overlapBottom - overlapTop; // vertical or horizontal Shift // TODO magic factor @@ -178,8 +183,8 @@ public class StoneTray implements IStoneTray { @Override public Iterator> iterator() { - final Iterator> entryIterator = objects.entrySet() - .iterator(); + final Iterator> entryIterator = objects + .entrySet().iterator(); return new Iterator>() { Iterator> iterator = entryIterator; @@ -225,4 +230,9 @@ public class StoneTray implements IStoneTray { return copy; } + @Override + public int getSize() { + return objects.size(); + } + } diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java new file mode 100644 index 0000000..2e6a7d0 --- /dev/null +++ b/test/jrummikub/control/RoundControlTest.java @@ -0,0 +1,24 @@ +package jrummikub.control; + +import static org.junit.Assert.*; +import jrummikub.model.GameState; +import jrummikub.view.MockView; + +import org.junit.Test; + +public class RoundControlTest { + + @Test + public void testDeal() { + MockView view = new MockView(); + GameState testGameState = new GameState(); + RoundControl testRound = new RoundControl(testGameState, view); + testRound.deal(); + assertEquals(106 - testGameState.getPlayerCount() * 14, testGameState + .getGameHeap().getSize()); + for (int i = 0; i < testGameState.getPlayerCount(); i++) { + assertEquals(14, testGameState.getPlayer(i).getHand().getSize()); + } + } + +} diff --git a/test/jrummikub/model/GameStateTest.java b/test/jrummikub/model/GameStateTest.java index 8887e78..a134231 100644 --- a/test/jrummikub/model/GameStateTest.java +++ b/test/jrummikub/model/GameStateTest.java @@ -18,13 +18,13 @@ public class GameStateTest { @Test public void nextActiveTest() { // All there? - assertEquals(4, testGame.players.size()); - assertSame(Color.red, testGame.activePlayer().getColor()); + assertEquals(4, testGame.getPlayerCount()); + assertSame(Color.red, testGame.getActivePlayer().getColor()); testGame.nextPlayer(); - assertSame(Color.yellow, testGame.activePlayer().getColor()); + assertSame(Color.yellow, testGame.getActivePlayer().getColor()); testGame.nextPlayer(); testGame.nextPlayer(); testGame.nextPlayer(); - assertSame(Color.red, testGame.activePlayer().getColor()); + assertSame(Color.red, testGame.getActivePlayer().getColor()); } } -- cgit v1.2.3