summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/RoundControl.java63
-rw-r--r--src/jrummikub/control/turn/HumanTurnControl.java2
2 files changed, 54 insertions, 11 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);
}
diff --git a/src/jrummikub/control/turn/HumanTurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java
index 2ab7b21..447c44d 100644
--- a/src/jrummikub/control/turn/HumanTurnControl.java
+++ b/src/jrummikub/control/turn/HumanTurnControl.java
@@ -441,12 +441,12 @@ public class HumanTurnControl extends AbstractTurnControl {
private void endOfTurn(boolean redeal) {
cleanUp();
+ view.setSelectedStones(new ArrayList<Stone>());
if (redeal) {
redealEvent.emit();
} else {
endOfTurnEvent.emit();
}
- view.setSelectedStones(new ArrayList<Stone>());
}
static private int compareJokers(Stone s1, Stone s2) {