diff options
Diffstat (limited to 'src/jrummikub/control/RoundControl.java')
-rw-r--r-- | src/jrummikub/control/RoundControl.java | 60 |
1 files changed, 37 insertions, 23 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index e18ce2e..ac3acf3 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -56,9 +56,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; @@ -93,7 +93,7 @@ public class RoundControl { * Continue a saved round after loading */ public void continueRound() { - + connections.add(view.getStartTurnEvent().add(new IListener() { @Override public void handle() { @@ -144,7 +144,7 @@ public class RoundControl { protected void doPrepareTurn() { updateSidePanel(); - + boolean isHuman = roundState.getActivePlayer().getPlayerSettings() .getType() == HUMAN; boolean oneHuman = roundState.getGameSettings().oneHuman(); @@ -160,11 +160,12 @@ public class RoundControl { } view.getTablePanel().setStoneSets(clonedTable.clone()); - view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() - .getName()); - view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() - .getColor()); - view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut()); + view.setCurrentPlayerName(roundState.getActivePlayer() + .getPlayerSettings().getName()); + view.setCurrentPlayerColor(roundState.getActivePlayer() + .getPlayerSettings().getColor()); + view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer() + .getLaidOut()); turnControl = createTurnControl(roundState.getActivePlayer() .getPlayerSettings()); @@ -193,8 +194,8 @@ public class RoundControl { } turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand, - roundState.getActivePlayer().getLaidOut(), turnMode), roundState - .getGameSettings(), view); + roundState.getActivePlayer().getLaidOut(), turnMode), + roundState.getGameSettings(), view); turnControl.getEndOfTurnEvent().add(new IListener1<ITable>() { @Override public void handle(ITable newTable) { @@ -211,16 +212,17 @@ public class RoundControl { turnControl.startTurn(); } - + private void updateSidePanel() { view.showSidePanel(true); view.getSidePanel().setGameSettings(roundState.getGameSettings()); List<IPlayer> players = new ArrayList<IPlayer>(); - for (int i = 1; i < roundState.getPlayerCount(); i ++) { + for (int i = 1; i < roundState.getPlayerCount(); i++) { players.add(roundState.getNthNextPlayer(-i)); } view.getSidePanel().setPlayers(players); - view.getSidePanel().setHeapCapacity(roundState.getGameSettings().getTotalStones()); + view.getSidePanel().setHeapCapacity( + roundState.getGameSettings().getTotalStones()); view.getSidePanel().setHeapSize(roundState.getGameHeap().getSize()); } @@ -235,11 +237,13 @@ public class RoundControl { void deal() { for (int i = 0; i < roundState.getPlayerCount(); i++) { IHand hand = roundState.getNthNextPlayer(i).getHand(); - for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) { - hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0)); + for (int j = 0; j < roundState.getGameSettings() + .getNumberOfStonesDealt(); j++) { + hand.drop(roundState.getGameHeap().drawStone(), new Position(0, + 0)); } } - + } private boolean laidOutValidPoints() { @@ -248,11 +252,13 @@ public class RoundControl { int totalValue = 0; for (StoneSet set : newSets) { - totalValue += set.classify(roundState.getGameSettings()).getSecond(); + totalValue += set.classify(roundState.getGameSettings()) + .getSecond(); } return totalValue == 0 - || totalValue >= roundState.getGameSettings().getInitialMeldThreshold(); + || totalValue >= roundState.getGameSettings() + .getInitialMeldThreshold(); } protected void endOfTurn(ITable newTable) { @@ -261,6 +267,11 @@ public class RoundControl { turnControl = null; + roundState.getActivePlayer().setLastTurnInvalid(false); + roundState.getActivePlayer().setLastTurnStoneCount( + roundState.getActivePlayer().getHand().getSize() + - clonedHand.getSize()); + roundState.getActivePlayer().setHand(clonedHand); boolean goToNextPlayer = true; lastTurnNotEnoughPoints = false; @@ -278,8 +289,8 @@ public class RoundControl { if (lastTurnNotEnoughPoints) { view.setInitialMeldError(roundState.getGameSettings() .getInitialMeldThreshold()); - view.setInvalidStoneSets(tableSetDifference(roundState.getTable(), - newTable)); + view.setInvalidStoneSets(tableSetDifference( + roundState.getTable(), newTable)); } else if (lastTurnMeldError) { view.setInitialMeldFirstError(); view.setInvalidStoneSets(touchedStoneSets(newTable)); @@ -379,6 +390,7 @@ public class RoundControl { Set<Stone> tableDiff = tableDifference(roundState.getTable(), newTable); // deal penalty, reset roundState.getGameHeap().putBack(tableDiff); + roundState.getActivePlayer().setLastTurnInvalid(true); dealPenalty(tableDiff.size()); } @@ -471,10 +483,12 @@ public class RoundControl { stonePoints = playerHand.isInitialMeldPossible(roundState .getGameSettings()) ? 200 : 100; } else { - stonePoints = playerHand.getStonePoints(roundState.getGameSettings()); + stonePoints = playerHand.getStonePoints(roundState + .getGameSettings()); } - bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize()); + bestScore = updateBestScore(bestScore, -stonePoints, + playerHand.getSize()); points.add(-stonePoints); pointSum += stonePoints; |