Feedback
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@461 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
c50fd5d701
commit
823ef9d4fe
10 changed files with 192 additions and 44 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Reference in a new issue