summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/RoundControl.java
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-18 04:39:16 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-18 04:39:16 +0200
commit823ef9d4fe63cb14a114dd01fda54387998071d5 (patch)
treedbf4f363eb9e0d8907dfd5d169e88e582cf1b61f /src/jrummikub/control/RoundControl.java
parentc50fd5d7016354fbd462078e7ae296e2bc5ed86e (diff)
downloadJRummikub-823ef9d4fe63cb14a114dd01fda54387998071d5.tar
JRummikub-823ef9d4fe63cb14a114dd01fda54387998071d5.zip
Feedback
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@461 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/RoundControl.java')
-rw-r--r--src/jrummikub/control/RoundControl.java63
1 files changed, 53 insertions, 10 deletions
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<Connection> connections = new ArrayList<Connection>();
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<Stone> markedStones = new ArrayList<Stone>();
+ for (Pair<StoneSet, Position> 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.<Stone> 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<Stone> 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<Integer, Integer> updateBestScore(
Pair<Integer, Integer> bestScore, int stonePoints, int size) {
if (bestScore.getFirst() == stonePoints) {
- return new Pair<Integer, Integer>(stonePoints, Math.min(bestScore
- .getSecond(), size));
+ return new Pair<Integer, Integer>(stonePoints, Math.min(
+ bestScore.getSecond(), size));
} else if (bestScore.getFirst() < stonePoints) {
return new Pair<Integer, Integer>(stonePoints, size);
}