Test redealing in RoundControl
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@286 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
531fe57b17
commit
f7743efa7d
4 changed files with 49 additions and 13 deletions
|
@ -15,7 +15,9 @@ import jrummikub.model.Score;
|
|||
import jrummikub.model.Stone;
|
||||
import jrummikub.model.StoneSet;
|
||||
import jrummikub.util.Connection;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.Event1;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.util.IEvent1;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.Pair;
|
||||
|
@ -28,6 +30,7 @@ public class RoundControl {
|
|||
private IRoundState roundState;
|
||||
private IView view;
|
||||
private ITable clonedTable;
|
||||
private Event restartRoundEvent = new Event();
|
||||
private Event1<Score> endOfRoundEvent = new Event1<Score>();
|
||||
private List<Connection> connections = new ArrayList<Connection>();
|
||||
private boolean roundFinished;
|
||||
|
@ -36,9 +39,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;
|
||||
|
@ -75,8 +78,8 @@ public class RoundControl {
|
|||
clonedTable = (ITable) roundState.getTable().clone();
|
||||
view.enableStartTurnPanel(true);
|
||||
view.getTablePanel().setStoneSets(clonedTable);
|
||||
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings()
|
||||
.getName());
|
||||
view.setCurrentPlayerName(roundState.getActivePlayer()
|
||||
.getPlayerSettings().getName());
|
||||
}
|
||||
|
||||
private void startTurn() {
|
||||
|
@ -97,8 +100,10 @@ public class RoundControl {
|
|||
for (int i = 0; i < roundState.getPlayerCount(); i++) {
|
||||
IHand hand = roundState.getNthNextPlayer(i).getHand();
|
||||
for (int j = 0; j < 7; j++) {
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(j, 0));
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(j, 1));
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(j,
|
||||
0));
|
||||
hand.drop(roundState.getGameHeap().drawStone(), new Position(j,
|
||||
1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +118,8 @@ public class RoundControl {
|
|||
}
|
||||
|
||||
return totalValue == 0
|
||||
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold();
|
||||
|| totalValue >= roundState.getGameSettings()
|
||||
.getInitialMeldThreshold();
|
||||
}
|
||||
|
||||
private void endOfTurn() {
|
||||
|
@ -149,7 +155,8 @@ public class RoundControl {
|
|||
}
|
||||
if (!roundState.getActivePlayer().getLaidOut()) {
|
||||
// Player touched forbidden stones
|
||||
if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) {
|
||||
if (!tableSetDifference(clonedTable, roundState.getTable())
|
||||
.isEmpty()) {
|
||||
rejectMove();
|
||||
return;
|
||||
}
|
||||
|
@ -158,7 +165,8 @@ public class RoundControl {
|
|||
return;
|
||||
}
|
||||
}
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
||||
clonedTable);
|
||||
|
||||
roundState.setTable(clonedTable);
|
||||
|
||||
|
@ -174,7 +182,8 @@ public class RoundControl {
|
|||
}
|
||||
|
||||
private void rejectMove() {
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable);
|
||||
Set<Stone> tableDiff = tableDifference(roundState.getTable(),
|
||||
clonedTable);
|
||||
// deal penalty, reset
|
||||
roundState.getGameHeap().putBack(tableDiff);
|
||||
dealPenalty(tableDiff.size());
|
||||
|
@ -266,7 +275,8 @@ public class RoundControl {
|
|||
stonePoints = playerHand.getStonePoints();
|
||||
}
|
||||
|
||||
bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize());
|
||||
bestScore = updateBestScore(bestScore, -stonePoints,
|
||||
playerHand.getSize());
|
||||
|
||||
points.add(-stonePoints);
|
||||
pointSum += stonePoints;
|
||||
|
@ -295,4 +305,13 @@ public class RoundControl {
|
|||
}
|
||||
return bestScore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Emitted when the round is aborted and needs to be restarted
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
public IEvent getRestartRoundEvent() {
|
||||
return restartRoundEvent;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,5 +42,5 @@ public interface IPlayerPanel {
|
|||
*
|
||||
* @return the event
|
||||
*/
|
||||
IEvent getRedealEvent();
|
||||
public IEvent getRedealEvent();
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ public interface IView {
|
|||
*
|
||||
* @return the event
|
||||
*/
|
||||
IEvent getFinalScoreEvent();
|
||||
public IEvent getFinalScoreEvent();
|
||||
|
||||
/**
|
||||
* The new round event is emitted when the player wants to start a new round
|
||||
|
|
|
@ -25,6 +25,7 @@ import jrummikub.model.Score;
|
|||
import jrummikub.model.Stone;
|
||||
import jrummikub.model.StoneSet;
|
||||
import jrummikub.model.Table;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.IListener1;
|
||||
import jrummikub.util.Pair;
|
||||
import jrummikub.view.MockView;
|
||||
|
@ -47,6 +48,7 @@ public class RoundControlTest {
|
|||
|
||||
private boolean roundEnded;
|
||||
private Score roundScore;
|
||||
protected boolean roundRestarted;
|
||||
|
||||
/**
|
||||
* For each test create a round control initialized by a mock model and view
|
||||
|
@ -888,4 +890,19 @@ public class RoundControlTest {
|
|||
assertFalse(14 == testRoundState.players.get(i).hand.getSize());
|
||||
}
|
||||
}
|
||||
|
||||
/** */
|
||||
@Test
|
||||
public void testRedeal() {
|
||||
testRound.getRestartRoundEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
roundRestarted = true;
|
||||
}
|
||||
});
|
||||
testRound.startRound();
|
||||
view.startTurnEvent.emit();
|
||||
view.playerPanel.redealEvent.emit();
|
||||
assertTrue(roundRestarted);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue