Allow laying out stone sets
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@180 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
b9fbe279c3
commit
b86571cf83
8 changed files with 209 additions and 125 deletions
|
@ -8,7 +8,7 @@ import jrummikub.util.Pair;
|
|||
|
||||
public class MockHand implements IHand {
|
||||
|
||||
public List<Stone> stones = new ArrayList<Stone>();
|
||||
public List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>();
|
||||
|
||||
public Iterable<Pair<Stone, Position>> iterable;
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class MockHand implements IHand {
|
|||
|
||||
@Override
|
||||
public void drop(Stone object, Position position) {
|
||||
stones.add(object);
|
||||
stones.add(new Pair<Stone, Position>(object, position));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +30,12 @@ public class MockHand implements IHand {
|
|||
|
||||
@Override
|
||||
public void pickUp(Stone object) {
|
||||
stones.remove(object);
|
||||
List<Pair<Stone, Position>> itList = new ArrayList(stones);
|
||||
for (Pair<Stone, Position> entry : itList) {
|
||||
if (entry.getFirst() == object) {
|
||||
stones.remove(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +45,11 @@ public class MockHand implements IHand {
|
|||
|
||||
@Override
|
||||
public Iterator<Pair<Stone, Position>> iterator() {
|
||||
return iterable.iterator();
|
||||
if (iterable != null) {
|
||||
return iterable.iterator();
|
||||
} else {
|
||||
return stones.iterator();
|
||||
}
|
||||
}
|
||||
|
||||
public MockHand clone() {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package jrummikub.view;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jrummikub.model.Position;
|
||||
import jrummikub.model.Stone;
|
||||
import jrummikub.util.Event2;
|
||||
|
@ -9,7 +12,7 @@ import jrummikub.util.Pair;
|
|||
|
||||
public class MockHandPanel implements IHandPanel {
|
||||
public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>();
|
||||
public Iterable<Pair<Stone, Position>> stones;
|
||||
public List<Pair<Stone, Position>> stones;
|
||||
|
||||
@Override
|
||||
public IEvent2<Stone, Boolean> getStoneClickEvent() {
|
||||
|
@ -36,7 +39,11 @@ public class MockHandPanel implements IHandPanel {
|
|||
|
||||
@Override
|
||||
public void setStones(Iterable<Pair<Stone, Position>> stones) {
|
||||
this.stones = stones;
|
||||
this.stones = new ArrayList<Pair<Stone, Position>>();
|
||||
|
||||
for (Pair<Stone, Position> entry : stones) {
|
||||
this.stones.add(entry);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,9 +31,9 @@ public class JRummikub {
|
|||
GameState gameState = new GameState();
|
||||
View view = new View();
|
||||
|
||||
for (Stone stone : gameState.getGameHeap().drawStones(5)) {
|
||||
/*for (Stone stone : gameState.getGameHeap().drawStones(5)) {
|
||||
gameState.getTable().drop(new StoneSet(stone), new Position(0, 0));
|
||||
}
|
||||
}*/
|
||||
|
||||
RoundControl roundControl = new RoundControl(gameState, view);
|
||||
roundControl.startRound();
|
||||
|
|
|
@ -12,6 +12,7 @@ import jrummikub.util.Connection;
|
|||
import jrummikub.util.Event;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.util.IListener;
|
||||
import jrummikub.util.IListener1;
|
||||
import jrummikub.util.IListener2;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
|
@ -59,8 +60,7 @@ public class TurnControl {
|
|||
|
||||
@Override
|
||||
public void handle(Stone stone, Boolean collect) {
|
||||
handStoneClick(stone, collect);
|
||||
|
||||
stoneClick(stone, collect);
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -72,6 +72,36 @@ public class TurnControl {
|
|||
collectionStoneClick(stone, collect);
|
||||
}
|
||||
}));
|
||||
connections.add(view.getTablePanel().getStoneClickEvent()
|
||||
.add(new IListener2<Stone, Boolean>() {
|
||||
|
||||
@Override
|
||||
public void handle(Stone stone, Boolean collect) {
|
||||
stoneClick(stone, collect);
|
||||
}
|
||||
}));
|
||||
|
||||
connections.add(view.getTablePanel().getClickEvent()
|
||||
.add(new IListener1<Position>() {
|
||||
@Override
|
||||
public void handle(Position pos) {
|
||||
tableClick(pos);
|
||||
}
|
||||
}));
|
||||
connections.add(view.getTablePanel().getLeftConnectorClickEvent()
|
||||
.add(new IListener1<StoneSet>() {
|
||||
@Override
|
||||
public void handle(StoneSet set) {
|
||||
leftConnectorClick(set);
|
||||
}
|
||||
}));
|
||||
connections.add(view.getTablePanel().getRightConnectorClickEvent()
|
||||
.add(new IListener1<StoneSet>() {
|
||||
@Override
|
||||
public void handle(StoneSet set) {
|
||||
rightConnectorClick(set);
|
||||
}
|
||||
}));
|
||||
|
||||
view.getPlayerPanel().getHandPanel().setStones(hand.clone());
|
||||
view.enableStartTurnPanel(false);
|
||||
|
@ -87,7 +117,7 @@ public class TurnControl {
|
|||
|
||||
}
|
||||
|
||||
private void handStoneClick(Stone stone, boolean collect) {
|
||||
private void stoneClick(Stone stone, boolean collect) {
|
||||
if (collect) {
|
||||
if (!selectedStones.remove(stone)) {
|
||||
selectedStones.add(stone);
|
||||
|
@ -109,17 +139,34 @@ public class TurnControl {
|
|||
|
||||
view.setSelectedStones(selectedStones);
|
||||
}
|
||||
|
||||
private void leftConnectorClick(StoneSet set){
|
||||
|
||||
|
||||
private void pickUpSelectedStones() {
|
||||
for (Stone stone : selectedStones) {
|
||||
hand.pickUp(stone);
|
||||
table.pickUpStone(stone);
|
||||
}
|
||||
}
|
||||
|
||||
private void rightConnectorClick(StoneSet set){
|
||||
|
||||
|
||||
private void tableClick(Position position) {
|
||||
if (selectedStones.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
pickUpSelectedStones();
|
||||
table.drop(new StoneSet(selectedStones), position);
|
||||
selectedStones.clear();
|
||||
|
||||
view.getTablePanel().setStoneSets(table);
|
||||
view.getPlayerPanel().getHandPanel().setStones(hand);
|
||||
view.setSelectedStones(selectedStones);
|
||||
}
|
||||
|
||||
private void tableClick(Position position){
|
||||
|
||||
|
||||
private void leftConnectorClick(StoneSet set) {
|
||||
|
||||
}
|
||||
|
||||
private void rightConnectorClick(StoneSet set) {
|
||||
|
||||
}
|
||||
|
||||
private void endOfTurn() {
|
||||
|
|
|
@ -14,7 +14,7 @@ import jrummikub.util.Pair;
|
|||
* Type of positioned objects (must implement Sizeable)
|
||||
*/
|
||||
public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
||||
protected HashMap<E, Position> objects = new HashMap<E, Position>();
|
||||
protected HashMap<E, Pair<E, Position>> objects = new HashMap<E, Pair<E, Position>>();
|
||||
|
||||
/** Possible move directions in case of overlapping Stones/Sets */
|
||||
|
||||
|
@ -29,8 +29,8 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
*/
|
||||
@Override
|
||||
public E pickUp(Position position) {
|
||||
for (Map.Entry<E, Position> i : objects.entrySet()) {
|
||||
Position currentPosition = i.getValue();
|
||||
for (Map.Entry<E, Pair<E, Position>> i : objects.entrySet()) {
|
||||
Position currentPosition = i.getValue().getSecond();
|
||||
E currentObject = i.getKey();
|
||||
// Tests if position is left of, above ... the current object
|
||||
if (position.getX() < currentPosition.getX()) {
|
||||
|
@ -68,10 +68,10 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void drop(E object, Position position, Direction direction) {
|
||||
for (Map.Entry<E, Position> i : ((Map<E, Position>) objects.clone())
|
||||
.entrySet()) {
|
||||
Position currentPosition = i.getValue();
|
||||
E currentObject = i.getKey();
|
||||
for (Pair<E, Position> i : ((Map<E, Pair<E, Position>>) objects.clone())
|
||||
.values()) {
|
||||
Position currentPosition = i.getSecond();
|
||||
E currentObject = i.getFirst();
|
||||
if (!objectsOverlap(object, position, currentObject,
|
||||
currentPosition)) {
|
||||
continue;
|
||||
|
@ -101,10 +101,10 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
break;
|
||||
}
|
||||
|
||||
objects.remove(i.getKey());
|
||||
objects.remove(i.getFirst());
|
||||
drop(currentObject, newPosition, direction);
|
||||
}
|
||||
objects.put(object, position);
|
||||
objects.put(object, new Pair<E, Position>(object, position));
|
||||
}
|
||||
|
||||
/** Tests whether two objects overlap **/
|
||||
|
@ -127,14 +127,14 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
}
|
||||
|
||||
private Direction getMoveDirection(E object, Position position,
|
||||
Map.Entry<E, Position> blocking) {
|
||||
boolean isVertical = getMoveOrientationn(object, position, blocking);
|
||||
Pair<E, Position> blocking) {
|
||||
boolean isVertical = getMoveOrientation(object, position, blocking);
|
||||
float objectMidpointX = position.getX() + object.getWidth() / 2;
|
||||
float objectMidpointY = position.getY() + object.getHeight() / 2;
|
||||
float blockingMidpointX = blocking.getValue().getX()
|
||||
+ blocking.getKey().getWidth() / 2;
|
||||
float blockingMidpointY = blocking.getValue().getY()
|
||||
+ blocking.getKey().getHeight() / 2;
|
||||
float blockingMidpointX = blocking.getSecond().getX()
|
||||
+ blocking.getFirst().getWidth() / 2;
|
||||
float blockingMidpointY = blocking.getSecond().getY()
|
||||
+ blocking.getFirst().getHeight() / 2;
|
||||
if (isVertical) {
|
||||
if (objectMidpointY < blockingMidpointY) {
|
||||
return Direction.BOTTOM;
|
||||
|
@ -150,21 +150,21 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean getMoveOrientationn(E object, Position position,
|
||||
Map.Entry<E, Position> blocking) {
|
||||
private boolean getMoveOrientation(E object, Position position,
|
||||
Pair<E, Position> blocking) {
|
||||
float objectRight = position.getX() + object.getWidth();
|
||||
float blockingRight = blocking.getValue().getX()
|
||||
+ blocking.getKey().getWidth();
|
||||
float blockingRight = blocking.getSecond().getX()
|
||||
+ blocking.getFirst().getWidth();
|
||||
float overlapRight = Math.min(objectRight, blockingRight);
|
||||
float overlapLeft = Math.max(position.getX(), blocking.getValue()
|
||||
float overlapLeft = Math.max(position.getX(), blocking.getSecond()
|
||||
.getX());
|
||||
float overlapX = overlapRight - overlapLeft;
|
||||
float objectBottom = position.getY() + object.getHeight();
|
||||
float blockingBottom = blocking.getValue().getY()
|
||||
+ blocking.getKey().getHeight();
|
||||
float blockingBottom = blocking.getSecond().getY()
|
||||
+ blocking.getFirst().getHeight();
|
||||
float overlapBottom = Math.min(objectBottom, blockingBottom);
|
||||
float overlapTop = Math
|
||||
.max(position.getY(), blocking.getValue().getY());
|
||||
.max(position.getY(), blocking.getSecond().getY());
|
||||
float overlapY = overlapBottom - overlapTop;
|
||||
// vertical or horizontal Shift
|
||||
// TODO magic factor
|
||||
|
@ -178,33 +178,12 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
*/
|
||||
@Override
|
||||
public Position getPosition(E object) {
|
||||
return objects.get(object);
|
||||
return objects.get(object).getSecond();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<Pair<E, Position>> iterator() {
|
||||
final Iterator<Map.Entry<E, Position>> entryIterator = objects
|
||||
.entrySet().iterator();
|
||||
return new Iterator<Pair<E, Position>>() {
|
||||
Iterator<Map.Entry<E, Position>> iterator = entryIterator;
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pair<E, Position> next() {
|
||||
Map.Entry<E, Position> entry = iterator.next();
|
||||
return new Pair<E, Position>(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
iterator.remove();
|
||||
}
|
||||
|
||||
};
|
||||
return objects.values().iterator();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -227,7 +206,7 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> {
|
|||
public IStoneTray<E> clone() {
|
||||
try {
|
||||
StoneTray<E> copy = (StoneTray<E>) super.clone();
|
||||
copy.objects = (HashMap<E, Position>) objects.clone();
|
||||
copy.objects = (HashMap<E, Pair<E, Position>>) objects.clone();
|
||||
|
||||
return copy;
|
||||
} catch (CloneNotSupportedException e) {
|
||||
|
|
|
@ -27,9 +27,7 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
|||
@Override
|
||||
public Pair<StoneSet, StoneSet> pickUpStone(Stone stone) {
|
||||
StoneInfo info = findStoneInfo(stone);
|
||||
|
||||
System.err.println("Stone: " + stone);
|
||||
|
||||
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -76,14 +74,10 @@ public class Table extends StoneTray<StoneSet> implements ITable {
|
|||
private Pair<StoneSet, StoneSet> splitSet(StoneSet set, Position setPosition,
|
||||
int stonePosition) {
|
||||
pickUp(set);
|
||||
|
||||
|
||||
Pair<StoneSet, StoneSet> firstSplit = set.splitAt(stonePosition);
|
||||
System.err.println("Size: " + set.size());
|
||||
System.err.println("stonePosition: " + stonePosition);
|
||||
System.err.println("Frist split: " + firstSplit.getFirst() + " " + firstSplit.getSecond());
|
||||
Pair<StoneSet, StoneSet> secondSplit = firstSplit.getSecond().splitAt(1);
|
||||
System.err.println("Second split: " + secondSplit.getFirst() + " " + secondSplit.getSecond());
|
||||
|
||||
|
||||
StoneSet leftSet = firstSplit.getFirst();
|
||||
StoneSet rightSet = secondSplit.getSecond();
|
||||
|
||||
|
|
|
@ -136,7 +136,7 @@ public class RoundControlTest {
|
|||
|
||||
view.startTurnEvent.emit();
|
||||
assertFalse(view.displayStartTurnPanel);
|
||||
Stone stone = testGameState.players.get(0).hand.stones.remove(0);
|
||||
Stone stone = testGameState.players.get(0).hand.stones.remove(0).getFirst();
|
||||
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
||||
resetTurnStart();
|
||||
view.getPlayerPanel().endTurnEvent.emit();
|
||||
|
@ -194,7 +194,7 @@ public class RoundControlTest {
|
|||
|
||||
view.startTurnEvent.emit();
|
||||
assertFalse(view.displayStartTurnPanel);
|
||||
Stone stone = testGameState.players.get(0).hand.stones.remove(0);
|
||||
Stone stone = testGameState.players.get(0).hand.stones.remove(0).getFirst();
|
||||
newTable.drop(new StoneSet(stone), new Position(0, 0));
|
||||
testGameState.players.get(0).hand.stones.clear();
|
||||
resetTurnStart();
|
||||
|
|
|
@ -10,8 +10,11 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import jrummikub.model.IHand;
|
||||
import jrummikub.model.ITable;
|
||||
import jrummikub.model.MockHand;
|
||||
import jrummikub.model.MockTable;
|
||||
import jrummikub.model.Position;
|
||||
|
@ -29,8 +32,8 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
public class TurnControlTest {
|
||||
static class AccessibleTable extends Table{
|
||||
StoneSet[] getSetArray(){
|
||||
static class AccessibleTable extends Table {
|
||||
StoneSet[] getSetArray() {
|
||||
return objects.keySet().toArray(new StoneSet[0]);
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +66,30 @@ public class TurnControlTest {
|
|||
MockHand mockHand;
|
||||
boolean eventFired;
|
||||
|
||||
private void checkTableDisplay(ITable table) {
|
||||
Iterator<Pair<StoneSet, Position>> stoneSetsView = mockView.tablePanel.stoneSets
|
||||
.iterator();
|
||||
Iterator<Pair<StoneSet, Position>> stoneSetsModel = table.iterator();
|
||||
|
||||
while (stoneSetsView.hasNext()) {
|
||||
assertTrue(stoneSetsModel.hasNext());
|
||||
assertSame(stoneSetsView.next(), stoneSetsModel.next());
|
||||
}
|
||||
assertFalse(stoneSetsModel.hasNext());
|
||||
}
|
||||
|
||||
private void checkHandDisplay(IHand hand) {
|
||||
Iterator<Pair<Stone, Position>> stoneSetsView = mockView.playerPanel.handPanel.stones
|
||||
.iterator();
|
||||
Iterator<Pair<Stone, Position>> stoneSetsModel = hand.iterator();
|
||||
|
||||
while (stoneSetsView.hasNext()) {
|
||||
assertTrue(stoneSetsModel.hasNext());
|
||||
assertSame(stoneSetsView.next(), stoneSetsModel.next());
|
||||
}
|
||||
assertFalse(stoneSetsModel.hasNext());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mockView = new MockView();
|
||||
|
@ -70,28 +97,23 @@ public class TurnControlTest {
|
|||
mockTable = new MockTable();
|
||||
mockHand = new MockHand();
|
||||
testControl = new TurnControl(mockHand, mockTable, mockView, mockTimer);
|
||||
testControl.startTurn();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startTimer() {
|
||||
testControl.startTurn();
|
||||
|
||||
assertTrue(mockTimer.timerRunning);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void showInitialHand() {
|
||||
mockView = new MockView();
|
||||
mockTimer = new MockTimer();
|
||||
mockTable = new MockTable();
|
||||
mockHand = new MockHand();
|
||||
|
||||
mockView.displayStartTurnPanel = true;
|
||||
|
||||
List<Pair<Stone, Position>> stones = Arrays
|
||||
.asList(new Pair<Stone, Position>(new Stone(RED), new Position(
|
||||
0, 0)), new Pair<Stone, Position>(new Stone(BLACK),
|
||||
new Position(1, 0)));
|
||||
List<Pair<Stone, Position>> stones = Arrays.asList(
|
||||
new Pair<Stone, Position>(new Stone(RED), new Position(0, 0)),
|
||||
new Pair<Stone, Position>(new Stone(BLACK), new Position(1, 0)));
|
||||
|
||||
mockHand.iterable = stones;
|
||||
|
||||
|
@ -111,6 +133,8 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void viewEndOfTurn() {
|
||||
testControl.startTurn();
|
||||
|
||||
eventFired = false;
|
||||
mockTimer.timerRunning = true;
|
||||
|
||||
|
@ -131,6 +155,8 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void timerEndOfTurn() {
|
||||
testControl.startTurn();
|
||||
|
||||
eventFired = false;
|
||||
mockTimer.timerRunning = true;
|
||||
|
||||
|
@ -150,6 +176,7 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void deselctOnEndOfTurn() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
|
@ -162,6 +189,7 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void selectStoneInHand() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
|
@ -180,6 +208,7 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void collectStoneInHand() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
|
@ -202,20 +231,23 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void deselectStoneInCollection() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
|
||||
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
|
||||
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
|
||||
firstStone, false);
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
|
||||
false);
|
||||
|
||||
assertCollection(Arrays.asList(secondStone));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void reorderCollection() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
|
@ -223,14 +255,15 @@ public class TurnControlTest {
|
|||
mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
|
||||
mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
|
||||
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(
|
||||
firstStone, true);
|
||||
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
|
||||
true);
|
||||
|
||||
assertCollection(Arrays.asList(secondStone, firstStone));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deselectWholeCollection() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
Stone secondStone = new Stone(StoneColor.BLACK);
|
||||
|
@ -246,6 +279,7 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void selectStoneOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
|
@ -264,6 +298,7 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void collectStoneOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone firstStone = new Stone(StoneColor.RED);
|
||||
|
||||
|
@ -286,6 +321,7 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void selectSetOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(StoneColor.RED);
|
||||
Stone stone2 = new Stone(StoneColor.BLACK);
|
||||
|
@ -305,6 +341,7 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void collectSetOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(StoneColor.RED);
|
||||
Stone stone2 = new Stone(StoneColor.BLACK);
|
||||
|
@ -324,13 +361,13 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void rangeSelectOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
Stone stone3 = new Stone(3, StoneColor.RED);
|
||||
Stone stone4 = new Stone(4, StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3,
|
||||
stone4));
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4));
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone3, set1);
|
||||
|
@ -344,14 +381,15 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void rangeCollectOnTable() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone extraStone = new Stone(StoneColor.RED);
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
Stone stone3 = new Stone(3, StoneColor.RED);
|
||||
Stone stone4 = new Stone(4, StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3,
|
||||
stone4));
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1, stone2, stone3, stone4));
|
||||
|
||||
mockTable.findStoneSet.put(stone1, set1);
|
||||
mockTable.findStoneSet.put(stone3, set1);
|
||||
|
@ -366,6 +404,8 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void rangeFailSelect() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
|
||||
|
@ -388,6 +428,8 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void rangeFailCollect() {
|
||||
testControl.startTurn();
|
||||
|
||||
Stone stone1 = new Stone(1, StoneColor.RED);
|
||||
Stone stone2 = new Stone(2, StoneColor.RED);
|
||||
StoneSet set1 = new StoneSet(Arrays.asList(stone1));
|
||||
|
@ -416,8 +458,9 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void testAddLeft() {
|
||||
AccessibleTable table=new AccessibleTable();
|
||||
TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
|
||||
AccessibleTable table = new AccessibleTable();
|
||||
TurnControl turnControl = new TurnControl(mockHand, table, mockView,
|
||||
mockTimer);
|
||||
turnControl.startTurn();
|
||||
Stone blueOne = new Stone(1, BLUE);
|
||||
Stone redOne = new Stone(1, RED);
|
||||
|
@ -432,10 +475,10 @@ public class TurnControlTest {
|
|||
Stone blackThree = new Stone(3, BLACK);
|
||||
Stone blackFour = new Stone(4, BLACK);
|
||||
Stone blackFive = new Stone(5, BLACK);
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
|
||||
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
|
||||
blackFive));
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
|
||||
redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(
|
||||
Arrays.asList(blueTwo, blackFour, blackFive));
|
||||
table.drop(oldSet1, new Position(0, 0));
|
||||
table.drop(oldSet2, new Position(0, 0));
|
||||
mockHand.drop(blueThree, new Position(0, 0));
|
||||
|
@ -446,7 +489,7 @@ public class TurnControlTest {
|
|||
mockView.tablePanel.leftConnectorClickEvent.emit(oldSet1);
|
||||
// handcheck
|
||||
assertEquals(1, mockHand.getSize());
|
||||
assertSame(mockHand.stones.get(0), blueFour);
|
||||
assertSame(mockHand.stones.get(0).getFirst(), blueFour);
|
||||
// tablecheck
|
||||
assertEquals(2, table.getSize());
|
||||
StoneSet newSet1, newSet2;
|
||||
|
@ -475,12 +518,12 @@ public class TurnControlTest {
|
|||
mockView.tablePanel.leftConnectorClickEvent.emit(oldSet2);
|
||||
// handcheck
|
||||
assertEquals(1, mockHand.getSize());
|
||||
assertSame(mockHand.stones.get(0), blueFour);
|
||||
assertSame(mockHand.stones.get(0).getFirst(), blueFour);
|
||||
// tablecheck
|
||||
assertEquals(2, table.getSize());
|
||||
if (table.getSetArray()[0].size() == 5) {
|
||||
newSet2 =table.getSetArray()[0];
|
||||
newSet1 =table.getSetArray()[1];
|
||||
newSet2 = table.getSetArray()[0];
|
||||
newSet1 = table.getSetArray()[1];
|
||||
} else {
|
||||
newSet1 = table.getSetArray()[0];
|
||||
newSet2 = table.getSetArray()[1];
|
||||
|
@ -529,8 +572,9 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void testAddRight() {
|
||||
AccessibleTable table=new AccessibleTable();
|
||||
TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
|
||||
AccessibleTable table = new AccessibleTable();
|
||||
TurnControl turnControl = new TurnControl(mockHand, table, mockView,
|
||||
mockTimer);
|
||||
turnControl.startTurn();
|
||||
Stone blueOne = new Stone(1, BLUE);
|
||||
Stone redOne = new Stone(1, RED);
|
||||
|
@ -545,10 +589,10 @@ public class TurnControlTest {
|
|||
Stone blackThree = new Stone(3, BLACK);
|
||||
Stone blackFour = new Stone(4, BLACK);
|
||||
Stone blackFive = new Stone(5, BLACK);
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
|
||||
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
|
||||
blackFive));
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
|
||||
redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(
|
||||
Arrays.asList(blueTwo, blackFour, blackFive));
|
||||
table.drop(oldSet1, new Position(0, 0));
|
||||
table.drop(oldSet2, new Position(0, 0));
|
||||
mockHand.drop(blueThree, new Position(0, 0));
|
||||
|
@ -559,7 +603,7 @@ public class TurnControlTest {
|
|||
mockView.tablePanel.rightConnectorClickEvent.emit(oldSet1);
|
||||
// handcheck
|
||||
assertEquals(1, mockHand.getSize());
|
||||
assertSame(mockHand.stones.get(0), blueFour);
|
||||
assertSame(mockHand.stones.get(0).getFirst(), blueFour);
|
||||
// tablecheck
|
||||
assertEquals(2, table.getSize());
|
||||
StoneSet newSet1, newSet2;
|
||||
|
@ -588,7 +632,7 @@ public class TurnControlTest {
|
|||
mockView.tablePanel.rightConnectorClickEvent.emit(oldSet2);
|
||||
// handcheck
|
||||
assertEquals(1, mockHand.getSize());
|
||||
assertSame(mockHand.stones.get(0), blueFour);
|
||||
assertSame(mockHand.stones.get(0).getFirst(), blueFour);
|
||||
// tablecheck
|
||||
assertEquals(2, table.getSize());
|
||||
if (table.getSetArray()[0].size() == 5) {
|
||||
|
@ -642,8 +686,9 @@ public class TurnControlTest {
|
|||
|
||||
@Test
|
||||
public void testAddNewSet() {
|
||||
AccessibleTable table=new AccessibleTable();
|
||||
TurnControl turnControl=new TurnControl(mockHand, table, mockView, mockTimer);
|
||||
AccessibleTable table = new AccessibleTable();
|
||||
TurnControl turnControl = new TurnControl(mockHand, table, mockView,
|
||||
mockTimer);
|
||||
turnControl.startTurn();
|
||||
Stone blueOne = new Stone(1, BLUE);
|
||||
Stone redOne = new Stone(1, RED);
|
||||
|
@ -658,10 +703,10 @@ public class TurnControlTest {
|
|||
Stone blackThree = new Stone(3, BLACK);
|
||||
Stone blackFour = new Stone(4, BLACK);
|
||||
Stone blackFive = new Stone(5, BLACK);
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne,
|
||||
blackOne, redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(Arrays.asList(blueTwo, blackFour,
|
||||
blackFive));
|
||||
StoneSet oldSet1 = new StoneSet(Arrays.asList(blueOne, redOne, blackOne,
|
||||
redTwo, redThree, redFour, blackTwo, blackThree));
|
||||
StoneSet oldSet2 = new StoneSet(
|
||||
Arrays.asList(blueTwo, blackFour, blackFive));
|
||||
table.drop(oldSet1, new Position(0, 0));
|
||||
table.drop(oldSet2, new Position(0, 0));
|
||||
mockHand.drop(blueThree, new Position(0, 0));
|
||||
|
@ -673,10 +718,10 @@ public class TurnControlTest {
|
|||
mockView.tablePanel.clickEvent.emit(new Position(0, 0));
|
||||
// handcheck
|
||||
assertEquals(1, mockHand.getSize());
|
||||
assertSame(blueFour, mockHand.stones.get(0));
|
||||
assertSame(blueFour, mockHand.stones.get(0).getFirst());
|
||||
// tablecheck
|
||||
StoneSet newSet1, newSet2, newSet3;
|
||||
assertEquals(2, table.getSize());
|
||||
assertEquals(3, table.getSize());
|
||||
if (table.getSetArray()[0].size() == 2) {
|
||||
newSet2 = table.getSetArray()[0];
|
||||
if (table.getSetArray()[1].size() == 4) {
|
||||
|
@ -701,7 +746,7 @@ public class TurnControlTest {
|
|||
newSet2 = table.getSetArray()[1];
|
||||
newSet3 = table.getSetArray()[2];
|
||||
} else {
|
||||
newSet2 =table.getSetArray()[2];
|
||||
newSet2 = table.getSetArray()[2];
|
||||
newSet3 = table.getSetArray()[1];
|
||||
}
|
||||
}
|
||||
|
@ -724,5 +769,8 @@ public class TurnControlTest {
|
|||
assertSame(newSet3.get(1), redOne);
|
||||
assertSame(newSet3.get(2), redThree);
|
||||
assertSame(newSet3.get(3), blueTwo);
|
||||
|
||||
checkTableDisplay(table);
|
||||
checkHandDisplay(mockHand);
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue