Table Difference Test gebaut, anfang Implementierung round control
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@143 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
433a0c3561
commit
f5075789fa
4 changed files with 71 additions and 19 deletions
|
@ -1,7 +1,5 @@
|
||||||
package jrummikub.view;
|
package jrummikub.view;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.model.StoneSet;
|
import jrummikub.model.StoneSet;
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
package jrummikub.control;
|
package jrummikub.control;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import jrummikub.model.IGameState;
|
import jrummikub.model.IGameState;
|
||||||
import jrummikub.model.IHand;
|
import jrummikub.model.IHand;
|
||||||
|
import jrummikub.model.ITable;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.util.IListener;
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
public class RoundControl {
|
public class RoundControl {
|
||||||
private IGameState gameState;
|
private IGameState gameState;
|
||||||
private IView view;
|
private IView view;
|
||||||
|
private ITable clonedTable;
|
||||||
|
|
||||||
public RoundControl(IGameState gameState, IView view) {
|
public RoundControl(IGameState gameState, IView view) {
|
||||||
this.gameState = gameState;
|
this.gameState = gameState;
|
||||||
|
@ -25,24 +30,32 @@ public class RoundControl {
|
||||||
startTurn();
|
startTurn();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
view.enableStartTurnPanel(true);
|
view.enableStartTurnPanel(true);
|
||||||
view.getTablePanel().setStoneSets(gameState.getTable().clone());
|
clonedTable = (ITable) gameState.getTable().clone();
|
||||||
|
view.getTablePanel().setStoneSets(clonedTable);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startTurn() {
|
private void startTurn() {
|
||||||
TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
|
TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
|
||||||
.getHand(), gameState.getTable(), view);
|
.getHand(), clonedTable, view);
|
||||||
|
turnControl.getEndOfTurnEvent().add(new IListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handle() {
|
||||||
|
endOfTurn();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// turnControl.startTurn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void deal() {
|
void deal() {
|
||||||
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, 0));
|
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
||||||
hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
|
0));
|
||||||
|
hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
|
||||||
|
1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,8 +64,8 @@ public class RoundControl {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ruleCheck() {
|
static Set<Stone> tableDifference(ITable oldTable, ITable newTable) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void resetTable() {
|
private void resetTable() {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package jrummikub.control;
|
package jrummikub.control;
|
||||||
|
|
||||||
|
import static jrummikub.model.StoneColor.BLACK;
|
||||||
|
import static jrummikub.model.StoneColor.BLUE;
|
||||||
|
import static jrummikub.model.StoneColor.RED;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
@ -7,7 +10,10 @@ import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import jrummikub.model.MockGameState;
|
import jrummikub.model.MockGameState;
|
||||||
import jrummikub.model.MockTable;
|
import jrummikub.model.MockTable;
|
||||||
|
@ -40,7 +46,8 @@ public class RoundControlTest {
|
||||||
|
|
||||||
private void checkCorrectlyDealed() {
|
private void checkCorrectlyDealed() {
|
||||||
assertEquals(106 - testGameState.getPlayerCount() * 14
|
assertEquals(106 - testGameState.getPlayerCount() * 14
|
||||||
- testGameState.table.getSize(), testGameState.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());
|
||||||
}
|
}
|
||||||
|
@ -196,4 +203,37 @@ public class RoundControlTest {
|
||||||
|
|
||||||
assertTrue(view.displayWinPanel);
|
assertTrue(view.displayWinPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTableDifference() {
|
||||||
|
MockTable oldTable = new MockTable();
|
||||||
|
MockTable newTable = new MockTable();
|
||||||
|
Stone blueOne = new Stone(1, BLUE);
|
||||||
|
Stone redOne = new Stone(1, RED);
|
||||||
|
Stone blackOne = new Stone(1, BLACK);
|
||||||
|
Stone blueTwo = new Stone(2, BLUE);
|
||||||
|
Stone blueThree = new Stone(3, BLUE);
|
||||||
|
Stone blueFour = new Stone(4, BLUE);
|
||||||
|
StoneSet oldSet1 = new StoneSet(
|
||||||
|
Arrays.asList(blueOne, redOne, blackOne));
|
||||||
|
StoneSet oldSet2 = new StoneSet(blueTwo);
|
||||||
|
oldTable.drop(oldSet1, new Position(0, 0));
|
||||||
|
oldTable.drop(oldSet2, new Position(0, 0));
|
||||||
|
StoneSet newSet1 = new StoneSet(Arrays.asList(blueOne, blueTwo,
|
||||||
|
blueFour));
|
||||||
|
StoneSet newSet2 = new StoneSet(Arrays.asList(redOne, blackOne,
|
||||||
|
blueThree));
|
||||||
|
newTable.drop(newSet1, new Position(0, 0));
|
||||||
|
newTable.drop(newSet2, new Position(0, 0));
|
||||||
|
|
||||||
|
Set<Stone> expectedStones = new HashSet<Stone>();
|
||||||
|
expectedStones.add(blueTwo);
|
||||||
|
expectedStones.add(blueThree);
|
||||||
|
expectedStones.add(blueFour);
|
||||||
|
|
||||||
|
Set<Stone> stones = RoundControl.tableDifference(oldTable, newTable);
|
||||||
|
|
||||||
|
assertTrue(expectedStones.containsAll(stones));
|
||||||
|
assertTrue(stones.containsAll(expectedStones));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
package jrummikub.model;
|
package jrummikub.model;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
import org.junit.*;
|
|
||||||
|
|
||||||
import static jrummikub.model.StoneColor.BLACK;
|
import static jrummikub.model.StoneColor.BLACK;
|
||||||
import static jrummikub.model.StoneColor.RED;
|
import static jrummikub.model.StoneColor.RED;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import jrummikub.model.Table;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TableTest {
|
public class TableTest {
|
||||||
Table testTable;
|
Table testTable;
|
||||||
|
|
Reference in a new issue