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:
Jannis Harder 2011-05-27 17:54:42 +02:00
parent 531fe57b17
commit f7743efa7d
4 changed files with 49 additions and 13 deletions

View file

@ -15,7 +15,9 @@ import jrummikub.model.Score;
import jrummikub.model.Stone; import jrummikub.model.Stone;
import jrummikub.model.StoneSet; import jrummikub.model.StoneSet;
import jrummikub.util.Connection; import jrummikub.util.Connection;
import jrummikub.util.Event;
import jrummikub.util.Event1; import jrummikub.util.Event1;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1; import jrummikub.util.IEvent1;
import jrummikub.util.IListener; import jrummikub.util.IListener;
import jrummikub.util.Pair; import jrummikub.util.Pair;
@ -28,6 +30,7 @@ public class RoundControl {
private IRoundState roundState; private IRoundState roundState;
private IView view; private IView view;
private ITable clonedTable; private ITable clonedTable;
private Event restartRoundEvent = new Event();
private Event1<Score> endOfRoundEvent = new Event1<Score>(); private Event1<Score> endOfRoundEvent = new Event1<Score>();
private List<Connection> connections = new ArrayList<Connection>(); private List<Connection> connections = new ArrayList<Connection>();
private boolean roundFinished; private boolean roundFinished;
@ -75,8 +78,8 @@ public class RoundControl {
clonedTable = (ITable) roundState.getTable().clone(); clonedTable = (ITable) roundState.getTable().clone();
view.enableStartTurnPanel(true); view.enableStartTurnPanel(true);
view.getTablePanel().setStoneSets(clonedTable); view.getTablePanel().setStoneSets(clonedTable);
view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() view.setCurrentPlayerName(roundState.getActivePlayer()
.getName()); .getPlayerSettings().getName());
} }
private void startTurn() { private void startTurn() {
@ -97,8 +100,10 @@ public class RoundControl {
for (int i = 0; i < roundState.getPlayerCount(); i++) { for (int i = 0; i < roundState.getPlayerCount(); i++) {
IHand hand = roundState.getNthNextPlayer(i).getHand(); IHand hand = roundState.getNthNextPlayer(i).getHand();
for (int j = 0; j < 7; j++) { for (int j = 0; j < 7; j++) {
hand.drop(roundState.getGameHeap().drawStone(), new Position(j, 0)); hand.drop(roundState.getGameHeap().drawStone(), new Position(j,
hand.drop(roundState.getGameHeap().drawStone(), new Position(j, 1)); 0));
hand.drop(roundState.getGameHeap().drawStone(), new Position(j,
1));
} }
} }
} }
@ -113,7 +118,8 @@ public class RoundControl {
} }
return totalValue == 0 return totalValue == 0
|| totalValue >= roundState.getGameSettings().getInitialMeldThreshold(); || totalValue >= roundState.getGameSettings()
.getInitialMeldThreshold();
} }
private void endOfTurn() { private void endOfTurn() {
@ -149,7 +155,8 @@ public class RoundControl {
} }
if (!roundState.getActivePlayer().getLaidOut()) { if (!roundState.getActivePlayer().getLaidOut()) {
// Player touched forbidden stones // Player touched forbidden stones
if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) { if (!tableSetDifference(clonedTable, roundState.getTable())
.isEmpty()) {
rejectMove(); rejectMove();
return; return;
} }
@ -158,7 +165,8 @@ public class RoundControl {
return; return;
} }
} }
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable); Set<Stone> tableDiff = tableDifference(roundState.getTable(),
clonedTable);
roundState.setTable(clonedTable); roundState.setTable(clonedTable);
@ -174,7 +182,8 @@ public class RoundControl {
} }
private void rejectMove() { private void rejectMove() {
Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable); Set<Stone> tableDiff = tableDifference(roundState.getTable(),
clonedTable);
// deal penalty, reset // deal penalty, reset
roundState.getGameHeap().putBack(tableDiff); roundState.getGameHeap().putBack(tableDiff);
dealPenalty(tableDiff.size()); dealPenalty(tableDiff.size());
@ -266,7 +275,8 @@ public class RoundControl {
stonePoints = playerHand.getStonePoints(); stonePoints = playerHand.getStonePoints();
} }
bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize()); bestScore = updateBestScore(bestScore, -stonePoints,
playerHand.getSize());
points.add(-stonePoints); points.add(-stonePoints);
pointSum += stonePoints; pointSum += stonePoints;
@ -295,4 +305,13 @@ public class RoundControl {
} }
return bestScore; return bestScore;
} }
/**
* Emitted when the round is aborted and needs to be restarted
*
* @return the event
*/
public IEvent getRestartRoundEvent() {
return restartRoundEvent;
}
} }

View file

@ -42,5 +42,5 @@ public interface IPlayerPanel {
* *
* @return the event * @return the event
*/ */
IEvent getRedealEvent(); public IEvent getRedealEvent();
} }

View file

@ -79,7 +79,7 @@ public interface IView {
* *
* @return the event * @return the event
*/ */
IEvent getFinalScoreEvent(); public IEvent getFinalScoreEvent();
/** /**
* The new round event is emitted when the player wants to start a new round * The new round event is emitted when the player wants to start a new round

View file

@ -25,6 +25,7 @@ import jrummikub.model.Score;
import jrummikub.model.Stone; import jrummikub.model.Stone;
import jrummikub.model.StoneSet; import jrummikub.model.StoneSet;
import jrummikub.model.Table; import jrummikub.model.Table;
import jrummikub.util.IListener;
import jrummikub.util.IListener1; import jrummikub.util.IListener1;
import jrummikub.util.Pair; import jrummikub.util.Pair;
import jrummikub.view.MockView; import jrummikub.view.MockView;
@ -47,6 +48,7 @@ public class RoundControlTest {
private boolean roundEnded; private boolean roundEnded;
private Score roundScore; private Score roundScore;
protected boolean roundRestarted;
/** /**
* For each test create a round control initialized by a mock model and view * 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()); 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);
}
} }