From f7743efa7ddf473a9ee24bfe7b69e0ccccdeacd5 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Fri, 27 May 2011 17:54:42 +0200 Subject: Test redealing in RoundControl git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@286 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 41 ++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 11 deletions(-) (limited to 'src/jrummikub/control/RoundControl.java') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 46ae459..c1997bb 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -15,7 +15,9 @@ import jrummikub.model.Score; import jrummikub.model.Stone; import jrummikub.model.StoneSet; import jrummikub.util.Connection; +import jrummikub.util.Event; import jrummikub.util.Event1; +import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IListener; import jrummikub.util.Pair; @@ -28,6 +30,7 @@ public class RoundControl { private IRoundState roundState; private IView view; private ITable clonedTable; + private Event restartRoundEvent = new Event(); private Event1 endOfRoundEvent = new Event1(); private List connections = new ArrayList(); private boolean roundFinished; @@ -36,9 +39,9 @@ public class RoundControl { * Create a new RoundControl using the given gameState and view * * @param roundState - * initial round state + * initial round state * @param view - * view used for user interaction + * view used for user interaction */ public RoundControl(IRoundState roundState, IView view) { this.roundState = roundState; @@ -75,8 +78,8 @@ public class RoundControl { clonedTable = (ITable) roundState.getTable().clone(); view.enableStartTurnPanel(true); view.getTablePanel().setStoneSets(clonedTable); - view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() - .getName()); + view.setCurrentPlayerName(roundState.getActivePlayer() + .getPlayerSettings().getName()); } private void startTurn() { @@ -97,8 +100,10 @@ public class RoundControl { for (int i = 0; i < roundState.getPlayerCount(); i++) { IHand hand = roundState.getNthNextPlayer(i).getHand(); for (int j = 0; j < 7; j++) { - hand.drop(roundState.getGameHeap().drawStone(), new Position(j, 0)); - hand.drop(roundState.getGameHeap().drawStone(), new Position(j, 1)); + hand.drop(roundState.getGameHeap().drawStone(), new Position(j, + 0)); + hand.drop(roundState.getGameHeap().drawStone(), new Position(j, + 1)); } } } @@ -113,7 +118,8 @@ public class RoundControl { } return totalValue == 0 - || totalValue >= roundState.getGameSettings().getInitialMeldThreshold(); + || totalValue >= roundState.getGameSettings() + .getInitialMeldThreshold(); } private void endOfTurn() { @@ -149,7 +155,8 @@ public class RoundControl { } if (!roundState.getActivePlayer().getLaidOut()) { // Player touched forbidden stones - if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) { + if (!tableSetDifference(clonedTable, roundState.getTable()) + .isEmpty()) { rejectMove(); return; } @@ -158,7 +165,8 @@ public class RoundControl { return; } } - Set tableDiff = tableDifference(roundState.getTable(), clonedTable); + Set tableDiff = tableDifference(roundState.getTable(), + clonedTable); roundState.setTable(clonedTable); @@ -174,7 +182,8 @@ public class RoundControl { } private void rejectMove() { - Set tableDiff = tableDifference(roundState.getTable(), clonedTable); + Set tableDiff = tableDifference(roundState.getTable(), + clonedTable); // deal penalty, reset roundState.getGameHeap().putBack(tableDiff); dealPenalty(tableDiff.size()); @@ -266,7 +275,8 @@ public class RoundControl { stonePoints = playerHand.getStonePoints(); } - bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize()); + bestScore = updateBestScore(bestScore, -stonePoints, + playerHand.getSize()); points.add(-stonePoints); pointSum += stonePoints; @@ -295,4 +305,13 @@ public class RoundControl { } return bestScore; } + + /** + * Emitted when the round is aborted and needs to be restarted + * + * @return the event + */ + public IEvent getRestartRoundEvent() { + return restartRoundEvent; + } } -- cgit v1.2.3