summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/JRummikub.java13
-rw-r--r--src/jrummikub/control/RoundControl.java26
-rw-r--r--test/jrummikub/control/RoundControlTest.java23
-rw-r--r--test/jrummikub/view/MockTablePanel.java5
4 files changed, 43 insertions, 24 deletions
diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java
index 38d152d..80d7080 100644
--- a/src/jrummikub/JRummikub.java
+++ b/src/jrummikub/JRummikub.java
@@ -2,9 +2,11 @@ package jrummikub;
import javax.swing.UIManager;
-import jrummikub.control.TurnControl;
+import jrummikub.control.RoundControl;
import jrummikub.model.GameState;
import jrummikub.model.Position;
+import jrummikub.model.Stone;
+import jrummikub.model.StoneSet;
import jrummikub.view.impl.View;
public class JRummikub {
@@ -20,11 +22,12 @@ public class JRummikub {
GameState gameState = new GameState();
View view = new View();
- gameState.getActivePlayer().getHand()
- .drop(gameState.getGameHeap().drawStone(), new Position(0, 0));
+ for (Stone stone : gameState.getGameHeap().drawStones(5)) {
+ gameState.getTable().drop(new StoneSet(stone), new Position(0, 0));
+ }
- TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
- .getHand(), gameState.getTable(), view);
+ RoundControl roundControl = new RoundControl(gameState, view);
+ roundControl.startRound();
}
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index a481991..2282666 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -2,8 +2,8 @@ package jrummikub.control;
import jrummikub.model.IGameState;
import jrummikub.model.IHand;
-import jrummikub.model.Player;
import jrummikub.model.Position;
+import jrummikub.util.IListener;
import jrummikub.view.IView;
public class RoundControl {
@@ -16,17 +16,33 @@ public class RoundControl {
}
public void startRound() {
+ deal();
+ view.getStartTurnEvent().add(new IListener() {
+
+ @Override
+ public void handle() {
+ startTurn();
+ }
+ });
+
+ view.enableStartTurnPanel(true);
+ view.getTablePanel().setStoneSets(gameState.getTable().clone());
+ }
+
+ private void startTurn() {
+ TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
+ .getHand(), gameState.getTable(), view);
+
+
}
void deal() {
for (int i = 0; i < gameState.getPlayerCount(); i++) {
IHand hand = gameState.getPlayer(i).getHand();
for (int j = 0; j < 7; j++) {
- hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
- 0));
- hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
- 1));
+ hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0));
+ hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
}
}
}
diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java
index caefb1f..caace50 100644
--- a/test/jrummikub/control/RoundControlTest.java
+++ b/test/jrummikub/control/RoundControlTest.java
@@ -9,7 +9,6 @@ import static org.junit.Assert.assertTrue;
import java.util.Iterator;
-import jrummikub.model.GameState;
import jrummikub.model.MockGameState;
import jrummikub.model.MockTable;
import jrummikub.model.Position;
@@ -35,13 +34,13 @@ public class RoundControlTest {
Stone stone = testGameState.getGameHeap().drawStone();
testGameState.table.drop(new StoneSet(stone), new Position(5, 0));
newTable = new MockTable();
- newTable.drop(new StoneSet(stone), new Position(5, 0));
-
+ newTable.sets.add(testGameState.table.sets.get(0));
+ testGameState.table.clonedTable = newTable;
}
private void checkCorrectlyDealed() {
- assertEquals(106 - testGameState.getPlayerCount() * 14 - testGameState.table.getSize(), testGameState
- .getGameHeap().getSize());
+ assertEquals(106 - testGameState.getPlayerCount() * 14
+ - testGameState.table.getSize(), testGameState.getGameHeap().getSize());
for (int i = 0; i < testGameState.getPlayerCount(); i++) {
assertEquals(14, testGameState.getPlayer(i).getHand().getSize());
}
@@ -56,12 +55,14 @@ public class RoundControlTest {
assertFalse(view.startTurnEvent.listeners.isEmpty());
checkTableDisplay();
}
-
+
private void checkTableDisplay() {
- Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets.iterator();
- Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table.sets.iterator();
-
- while(stoneSetsView.hasNext()) {
+ Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets
+ .iterator();
+ Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table.sets
+ .iterator();
+
+ while (stoneSetsView.hasNext()) {
assertTrue(stoneSetsModel.hasNext());
assertSame(stoneSetsView.next(), stoneSetsModel.next());
}
@@ -89,7 +90,7 @@ public class RoundControlTest {
checkTurnStartSetUp();
}
-
+
@Test
public void testTableDisplay() {
testRound.startRound();
diff --git a/test/jrummikub/view/MockTablePanel.java b/test/jrummikub/view/MockTablePanel.java
index 151cc7e..c32946f 100644
--- a/test/jrummikub/view/MockTablePanel.java
+++ b/test/jrummikub/view/MockTablePanel.java
@@ -21,7 +21,7 @@ public class MockTablePanel implements ITablePanel {
public String leftPlayerName;
public String topPlayerName;
public String rightPlayerName;
-
+
public Iterable<Pair<StoneSet, Position>> stoneSets;
@Override
@@ -65,8 +65,7 @@ public class MockTablePanel implements ITablePanel {
@Override
public void setStoneSets(Iterable<Pair<StoneSet, Position>> stoneSets) {
- // TODO Auto-generated method stub
-
+ this.stoneSets = stoneSets;
}
@Override