From 823ef9d4fe63cb14a114dd01fda54387998071d5 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Sat, 18 Jun 2011 04:39:16 +0200 Subject: Feedback git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@461 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 63 +++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 10 deletions(-) (limited to 'src/jrummikub/control/RoundControl.java') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 3c50819..f060420 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -3,6 +3,7 @@ package jrummikub.control; import static jrummikub.model.PlayerSettings.Type.*; import java.util.ArrayList; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -42,6 +43,8 @@ public class RoundControl { private List connections = new ArrayList(); private ITurnControl turnControl; private boolean roundFinished; + private boolean lastTurnNotEnoughPoints; + private boolean lastTurnMeldError; /** * Create a new RoundControl using the given gameState and view @@ -84,6 +87,13 @@ public class RoundControl { } })); + connections.add(view.getAcknowledgeInvalidEvent().add(new IListener() { + @Override + public void handle() { + nextPlayer(); + } + })); + prepareTurn(); } @@ -139,6 +149,7 @@ public class RoundControl { TurnMode turnMode = TurnMode.NORMAL_TURN; if (roundState.getTurnNumber() < 1) { + view.setStoneCollectionHidden(true); turnMode = TurnMode.INSPECT_ONLY; if (clonedHand.getIdenticalStoneCount() >= 3) { turnMode = TurnMode.MAY_REDEAL; @@ -199,10 +210,39 @@ public class RoundControl { private void endOfTurn() { turnControl = null; roundState.getActivePlayer().setHand(clonedHand); + boolean goToNextPlayer = true; + lastTurnNotEnoughPoints = false; + lastTurnMeldError = false; if (roundState.getTurnNumber() >= 1) { - checkTurn(); - } + goToNextPlayer = checkTurn(); + } + if (goToNextPlayer) { + nextPlayer(); + } else { + view.setBottomPanel(BottomPanelType.INVALID_TURN_PANEL); + if (lastTurnNotEnoughPoints) { + view.setInitialMeldError(roundState.getGameSettings() + .getInitialMeldThreshold()); + } else if (lastTurnMeldError) { + view.setInitialMeldFirstError(); + } else { + List markedStones = new ArrayList(); + for (Pair set : clonedTable) { + if (!set.getFirst().isValid(roundState.getGameSettings())) { + for (Stone stone : set.getFirst()) { + markedStones.add(stone); + } + } + } + view.setStoneCollectionHidden(true); + view.setSelectedStones(markedStones); + } + } + } + private void nextPlayer() { + view.setSelectedStones(Collections. emptyList()); + view.setStoneCollectionHidden(false); if (roundState.getLastPlayer() == null) { if (roundState.getGameHeap().getSize() == 0) { roundState.setLastPlayer(roundState.getNthNextPlayer(0)); @@ -225,21 +265,23 @@ public class RoundControl { } } - private void checkTurn() { + private boolean checkTurn() { if (!clonedTable.isValid()) { rejectMove(); - return; + return false; } if (!roundState.getActivePlayer().getLaidOut()) { // Player touched forbidden stones if (!tableSetDifference(clonedTable, roundState.getTable()) .isEmpty()) { rejectMove(); - return; + lastTurnMeldError = true; + return false; } if (!laidOutValidPoints()) { rejectMove(); - return; + lastTurnNotEnoughPoints = true; + return false; } } Set tableDiff = tableDifference(roundState.getTable(), @@ -256,6 +298,7 @@ public class RoundControl { endOfRound(); } } + return true; } private void rejectMove() { @@ -358,8 +401,8 @@ public class RoundControl { .getGameSettings()); } - bestScore = updateBestScore(bestScore, -stonePoints, playerHand - .getSize()); + bestScore = updateBestScore(bestScore, -stonePoints, + playerHand.getSize()); points.add(-stonePoints); pointSum += stonePoints; @@ -381,8 +424,8 @@ public class RoundControl { private static Pair updateBestScore( Pair bestScore, int stonePoints, int size) { if (bestScore.getFirst() == stonePoints) { - return new Pair(stonePoints, Math.min(bestScore - .getSecond(), size)); + return new Pair(stonePoints, Math.min( + bestScore.getSecond(), size)); } else if (bestScore.getFirst() < stonePoints) { return new Pair(stonePoints, size); } -- cgit v1.2.3