Implemented stone display in both controls, tested (weniger Mock-Mist)
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@140 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
866197f315
commit
121afdf6c6
4 changed files with 43 additions and 24 deletions
|
@ -2,9 +2,11 @@ package jrummikub;
|
||||||
|
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
|
|
||||||
import jrummikub.control.TurnControl;
|
import jrummikub.control.RoundControl;
|
||||||
import jrummikub.model.GameState;
|
import jrummikub.model.GameState;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
|
import jrummikub.model.Stone;
|
||||||
|
import jrummikub.model.StoneSet;
|
||||||
import jrummikub.view.impl.View;
|
import jrummikub.view.impl.View;
|
||||||
|
|
||||||
public class JRummikub {
|
public class JRummikub {
|
||||||
|
@ -20,11 +22,12 @@ public class JRummikub {
|
||||||
GameState gameState = new GameState();
|
GameState gameState = new GameState();
|
||||||
View view = new View();
|
View view = new View();
|
||||||
|
|
||||||
gameState.getActivePlayer().getHand()
|
for (Stone stone : gameState.getGameHeap().drawStones(5)) {
|
||||||
.drop(gameState.getGameHeap().drawStone(), new Position(0, 0));
|
gameState.getTable().drop(new StoneSet(stone), new Position(0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
|
RoundControl roundControl = new RoundControl(gameState, view);
|
||||||
.getHand(), gameState.getTable(), view);
|
roundControl.startRound();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@ package jrummikub.control;
|
||||||
|
|
||||||
import jrummikub.model.IGameState;
|
import jrummikub.model.IGameState;
|
||||||
import jrummikub.model.IHand;
|
import jrummikub.model.IHand;
|
||||||
import jrummikub.model.Player;
|
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
public class RoundControl {
|
public class RoundControl {
|
||||||
|
@ -16,6 +16,24 @@ public class RoundControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startRound() {
|
public void startRound() {
|
||||||
|
deal();
|
||||||
|
|
||||||
|
view.getStartTurnEvent().add(new IListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle() {
|
||||||
|
startTurn();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
view.enableStartTurnPanel(true);
|
||||||
|
view.getTablePanel().setStoneSets(gameState.getTable().clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void startTurn() {
|
||||||
|
TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
|
||||||
|
.getHand(), gameState.getTable(), view);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,10 +41,8 @@ public class RoundControl {
|
||||||
for (int i = 0; i < gameState.getPlayerCount(); i++) {
|
for (int i = 0; i < gameState.getPlayerCount(); i++) {
|
||||||
IHand hand = gameState.getPlayer(i).getHand();
|
IHand hand = gameState.getPlayer(i).getHand();
|
||||||
for (int j = 0; j < 7; j++) {
|
for (int j = 0; j < 7; j++) {
|
||||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0));
|
||||||
0));
|
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
|
||||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
|
||||||
1));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import jrummikub.model.GameState;
|
|
||||||
import jrummikub.model.MockGameState;
|
import jrummikub.model.MockGameState;
|
||||||
import jrummikub.model.MockTable;
|
import jrummikub.model.MockTable;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
|
@ -35,13 +34,13 @@ public class RoundControlTest {
|
||||||
Stone stone = testGameState.getGameHeap().drawStone();
|
Stone stone = testGameState.getGameHeap().drawStone();
|
||||||
testGameState.table.drop(new StoneSet(stone), new Position(5, 0));
|
testGameState.table.drop(new StoneSet(stone), new Position(5, 0));
|
||||||
newTable = new MockTable();
|
newTable = new MockTable();
|
||||||
newTable.drop(new StoneSet(stone), new Position(5, 0));
|
newTable.sets.add(testGameState.table.sets.get(0));
|
||||||
|
testGameState.table.clonedTable = newTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkCorrectlyDealed() {
|
private void checkCorrectlyDealed() {
|
||||||
assertEquals(106 - testGameState.getPlayerCount() * 14 - testGameState.table.getSize(), testGameState
|
assertEquals(106 - testGameState.getPlayerCount() * 14
|
||||||
.getGameHeap().getSize());
|
- testGameState.table.getSize(), testGameState.getGameHeap().getSize());
|
||||||
for (int i = 0; i < testGameState.getPlayerCount(); i++) {
|
for (int i = 0; i < testGameState.getPlayerCount(); i++) {
|
||||||
assertEquals(14, testGameState.getPlayer(i).getHand().getSize());
|
assertEquals(14, testGameState.getPlayer(i).getHand().getSize());
|
||||||
}
|
}
|
||||||
|
@ -58,10 +57,12 @@ public class RoundControlTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkTableDisplay() {
|
private void checkTableDisplay() {
|
||||||
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets.iterator();
|
Iterator<Pair<StoneSet, Position>> stoneSetsView = view.tablePanel.stoneSets
|
||||||
Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table.sets.iterator();
|
.iterator();
|
||||||
|
Iterator<Pair<StoneSet, Position>> stoneSetsModel = testGameState.table.sets
|
||||||
|
.iterator();
|
||||||
|
|
||||||
while(stoneSetsView.hasNext()) {
|
while (stoneSetsView.hasNext()) {
|
||||||
assertTrue(stoneSetsModel.hasNext());
|
assertTrue(stoneSetsModel.hasNext());
|
||||||
assertSame(stoneSetsView.next(), stoneSetsModel.next());
|
assertSame(stoneSetsView.next(), stoneSetsModel.next());
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,8 +65,7 @@ public class MockTablePanel implements ITablePanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStoneSets(Iterable<Pair<StoneSet, Position>> stoneSets) {
|
public void setStoneSets(Iterable<Pair<StoneSet, Position>> stoneSets) {
|
||||||
// TODO Auto-generated method stub
|
this.stoneSets = stoneSets;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Reference in a new issue