Renamed win() and fixed end of round tests

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@267 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-24 22:16:16 +02:00
parent 8c3c66f361
commit 81ca3e174a
3 changed files with 32 additions and 12 deletions

View file

@ -63,7 +63,7 @@ public class GameControl {
roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer()); roundState.setActivePlayerNumber(gameState.getFirstRoundFirstPlayer());
roundControl = new RoundControl(roundState, view); roundControl = new RoundControl(roundState, view);
roundControl.getEndRoundEvent().add(new IListener() { roundControl.getEndOfRoundEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {

View file

@ -26,7 +26,7 @@ public class RoundControl {
private IRoundState roundState; private IRoundState roundState;
private IView view; private IView view;
private ITable clonedTable; private ITable clonedTable;
private Event endRoundEvent = new Event(); private Event endOfRoundEvent = new Event();
private List<Connection> connections = new ArrayList<Connection>(); private List<Connection> connections = new ArrayList<Connection>();
private boolean roundFinished; private boolean roundFinished;
@ -46,10 +46,10 @@ public class RoundControl {
/** /**
* End the round * End the round
* *
* @return endRoundEvent * @return endOfRoundEvent
*/ */
public IEvent getEndRoundEvent() { public IEvent getEndOfRoundEvent() {
return endRoundEvent; return endOfRoundEvent;
} }
/** /**
@ -134,7 +134,7 @@ public class RoundControl {
} else { } else {
if (roundState.getActivePlayer() == roundState.getLastPlayer()) { if (roundState.getActivePlayer() == roundState.getLastPlayer()) {
// TODO check who has won // TODO check who has won
win(); endOfRound();
} else { } else {
roundState.nextPlayer(); roundState.nextPlayer();
} }
@ -171,7 +171,7 @@ public class RoundControl {
} else { } else {
roundState.getActivePlayer().setLaidOut(true); roundState.getActivePlayer().setLaidOut(true);
if (roundState.getActivePlayer().getHand().getSize() == 0) { if (roundState.getActivePlayer().getHand().getSize() == 0) {
win(); endOfRound();
} }
} }
} }
@ -235,11 +235,11 @@ public class RoundControl {
dealStones(count + 3); dealStones(count + 3);
} }
private void win() { private void endOfRound() {
for (Connection c : connections) { for (Connection c : connections) {
c.remove(); c.remove();
} }
endRoundEvent.emit(); endOfRoundEvent.emit();
view.enableWinPanel(true); view.enableWinPanel(true);
roundFinished = true; roundFinished = true;
} }

View file

@ -32,6 +32,7 @@ import jrummikub.model.RoundState;
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.Pair; import jrummikub.util.Pair;
import jrummikub.view.MockView; import jrummikub.view.MockView;
@ -50,6 +51,8 @@ public class RoundControlTest {
private GameSettings gameSettings; private GameSettings gameSettings;
private IRoundState roundState; private IRoundState roundState;
private RoundControl roundControl; private RoundControl roundControl;
private boolean roundEnded;
/** /**
* 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
@ -64,6 +67,7 @@ public class RoundControlTest {
testTable = new MockTable(); testTable = new MockTable();
testTable.sets.add(testRoundState.table.sets.get(0)); testTable.sets.add(testRoundState.table.sets.get(0));
testRoundState.table.clonedTable = testTable; testRoundState.table.clonedTable = testTable;
roundEnded = false;
gameSettings = new GameSettings(); gameSettings = new GameSettings();
@ -566,6 +570,14 @@ public class RoundControlTest {
/** */ /** */
@Test @Test
public void testWinning() { public void testWinning() {
testRound.getEndOfRoundEvent().add(new IListener() {
@Override
public void handle() {
roundEnded = true;
}
});
testRound.startRound(); testRound.startRound();
MockTable oldTable = testRoundState.table; MockTable oldTable = testRoundState.table;
testTable.valid = true; testTable.valid = true;
@ -594,9 +606,10 @@ public class RoundControlTest {
testRoundState.players.get(0).hand = new Hand(gameSettings); testRoundState.players.get(0).hand = new Hand(gameSettings);
resetTurnStart(); resetTurnStart();
view.playerPanel.endTurnEvent.emit();
assertTrue(view.displayWinPanel); assertFalse(roundEnded);
view.playerPanel.endTurnEvent.emit();
assertTrue(roundEnded);
} }
/** */ /** */
@ -687,6 +700,13 @@ public class RoundControlTest {
/** */ /** */
@Test @Test
public void heapIsEmpty() { public void heapIsEmpty() {
roundControl.getEndOfRoundEvent().add(new IListener() {
@Override
public void handle() {
roundEnded = true;
}
});
roundState.getGameHeap().drawStones(106 - 14 * 4 - 1); roundState.getGameHeap().drawStones(106 - 14 * 4 - 1);
roundControl.startRound(); roundControl.startRound();
@ -702,6 +722,6 @@ public class RoundControlTest {
view.startTurnEvent.emit(); view.startTurnEvent.emit();
view.playerPanel.endTurnEvent.emit(); view.playerPanel.endTurnEvent.emit();
} }
assertTrue(view.displayWinPanel); assertTrue(roundEnded);
} }
} }