From b86571cf832ff13010798f3607eea6ad0ef039d0 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 9 May 2011 00:33:34 +0200 Subject: Allow laying out stone sets git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@180 72836036-5685-4462-b002-a69064685172 --- mock/jrummikub/model/MockHand.java | 17 +++- mock/jrummikub/view/MockHandPanel.java | 11 ++- src/jrummikub/JRummikub.java | 4 +- src/jrummikub/control/TurnControl.java | 71 +++++++++++--- src/jrummikub/model/StoneTray.java | 73 +++++--------- src/jrummikub/model/Table.java | 12 +-- test/jrummikub/control/RoundControlTest.java | 4 +- test/jrummikub/control/TurnControlTest.java | 142 ++++++++++++++++++--------- 8 files changed, 209 insertions(+), 125 deletions(-) diff --git a/mock/jrummikub/model/MockHand.java b/mock/jrummikub/model/MockHand.java index dc4dd04..994f7f5 100644 --- a/mock/jrummikub/model/MockHand.java +++ b/mock/jrummikub/model/MockHand.java @@ -8,7 +8,7 @@ import jrummikub.util.Pair; public class MockHand implements IHand { - public List stones = new ArrayList(); + public List> stones = new ArrayList>(); public Iterable> 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(object, position)); } @Override @@ -30,7 +30,12 @@ public class MockHand implements IHand { @Override public void pickUp(Stone object) { - stones.remove(object); + List> itList = new ArrayList(stones); + for (Pair entry : itList) { + if (entry.getFirst() == object) { + stones.remove(entry); + } + } } @Override @@ -40,7 +45,11 @@ public class MockHand implements IHand { @Override public Iterator> iterator() { - return iterable.iterator(); + if (iterable != null) { + return iterable.iterator(); + } else { + return stones.iterator(); + } } public MockHand clone() { diff --git a/mock/jrummikub/view/MockHandPanel.java b/mock/jrummikub/view/MockHandPanel.java index 4fdd58e..42bc41e 100644 --- a/mock/jrummikub/view/MockHandPanel.java +++ b/mock/jrummikub/view/MockHandPanel.java @@ -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 stoneClickEvent = new Event2(); - public Iterable> stones; + public List> stones; @Override public IEvent2 getStoneClickEvent() { @@ -36,7 +39,11 @@ public class MockHandPanel implements IHandPanel { @Override public void setStones(Iterable> stones) { - this.stones = stones; + this.stones = new ArrayList>(); + + for (Pair entry : stones) { + this.stones.add(entry); + } } } diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java index a913e2a..be4bf24 100644 --- a/src/jrummikub/JRummikub.java +++ b/src/jrummikub/JRummikub.java @@ -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(); diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index a71e56c..3213fd6 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -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() { + + @Override + public void handle(Stone stone, Boolean collect) { + stoneClick(stone, collect); + } + })); + + connections.add(view.getTablePanel().getClickEvent() + .add(new IListener1() { + @Override + public void handle(Position pos) { + tableClick(pos); + } + })); + connections.add(view.getTablePanel().getLeftConnectorClickEvent() + .add(new IListener1() { + @Override + public void handle(StoneSet set) { + leftConnectorClick(set); + } + })); + connections.add(view.getTablePanel().getRightConnectorClickEvent() + .add(new IListener1() { + @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 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 rightConnectorClick(StoneSet set){ - + + private void leftConnectorClick(StoneSet set) { + } - - private void tableClick(Position position){ - + + private void rightConnectorClick(StoneSet set) { + } private void endOfTurn() { diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index 14e9026..94b09be 100644 --- a/src/jrummikub/model/StoneTray.java +++ b/src/jrummikub/model/StoneTray.java @@ -14,7 +14,7 @@ import jrummikub.util.Pair; * Type of positioned objects (must implement Sizeable) */ public class StoneTray implements IStoneTray { - protected HashMap objects = new HashMap(); + protected HashMap> objects = new HashMap>(); /** Possible move directions in case of overlapping Stones/Sets */ @@ -29,8 +29,8 @@ public class StoneTray implements IStoneTray { */ @Override public E pickUp(Position position) { - for (Map.Entry i : objects.entrySet()) { - Position currentPosition = i.getValue(); + for (Map.Entry> 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 implements IStoneTray { @SuppressWarnings("unchecked") private void drop(E object, Position position, Direction direction) { - for (Map.Entry i : ((Map) objects.clone()) - .entrySet()) { - Position currentPosition = i.getValue(); - E currentObject = i.getKey(); + for (Pair i : ((Map>) 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 implements IStoneTray { break; } - objects.remove(i.getKey()); + objects.remove(i.getFirst()); drop(currentObject, newPosition, direction); } - objects.put(object, position); + objects.put(object, new Pair(object, position)); } /** Tests whether two objects overlap **/ @@ -127,14 +127,14 @@ public class StoneTray implements IStoneTray { } private Direction getMoveDirection(E object, Position position, - Map.Entry blocking) { - boolean isVertical = getMoveOrientationn(object, position, blocking); + Pair 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 implements IStoneTray { } } - private boolean getMoveOrientationn(E object, Position position, - Map.Entry blocking) { + private boolean getMoveOrientation(E object, Position position, + Pair 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 implements IStoneTray { */ @Override public Position getPosition(E object) { - return objects.get(object); + return objects.get(object).getSecond(); } @Override public Iterator> iterator() { - final Iterator> entryIterator = objects - .entrySet().iterator(); - return new Iterator>() { - Iterator> iterator = entryIterator; - - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - @Override - public Pair next() { - Map.Entry entry = iterator.next(); - return new Pair(entry.getKey(), entry.getValue()); - } - - @Override - public void remove() { - iterator.remove(); - } - - }; + return objects.values().iterator(); } /* @@ -227,7 +206,7 @@ public class StoneTray implements IStoneTray { public IStoneTray clone() { try { StoneTray copy = (StoneTray) super.clone(); - copy.objects = (HashMap) objects.clone(); + copy.objects = (HashMap>) objects.clone(); return copy; } catch (CloneNotSupportedException e) { diff --git a/src/jrummikub/model/Table.java b/src/jrummikub/model/Table.java index df50bbf..58c65a6 100644 --- a/src/jrummikub/model/Table.java +++ b/src/jrummikub/model/Table.java @@ -27,9 +27,7 @@ public class Table extends StoneTray implements ITable { @Override public Pair 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 implements ITable { private Pair splitSet(StoneSet set, Position setPosition, int stonePosition) { pickUp(set); - + Pair 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 secondSplit = firstSplit.getSecond().splitAt(1); - System.err.println("Second split: " + secondSplit.getFirst() + " " + secondSplit.getSecond()); - + StoneSet leftSet = firstSplit.getFirst(); StoneSet rightSet = secondSplit.getSecond(); diff --git a/test/jrummikub/control/RoundControlTest.java b/test/jrummikub/control/RoundControlTest.java index 9569fbd..38060c0 100644 --- a/test/jrummikub/control/RoundControlTest.java +++ b/test/jrummikub/control/RoundControlTest.java @@ -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(); diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java index 9617233..0335bc7 100644 --- a/test/jrummikub/control/TurnControlTest.java +++ b/test/jrummikub/control/TurnControlTest.java @@ -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> stoneSetsView = mockView.tablePanel.stoneSets + .iterator(); + Iterator> stoneSetsModel = table.iterator(); + + while (stoneSetsView.hasNext()) { + assertTrue(stoneSetsModel.hasNext()); + assertSame(stoneSetsView.next(), stoneSetsModel.next()); + } + assertFalse(stoneSetsModel.hasNext()); + } + + private void checkHandDisplay(IHand hand) { + Iterator> stoneSetsView = mockView.playerPanel.handPanel.stones + .iterator(); + Iterator> 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> stones = Arrays - .asList(new Pair(new Stone(RED), new Position( - 0, 0)), new Pair(new Stone(BLACK), - new Position(1, 0))); + List> stones = Arrays.asList( + new Pair(new Stone(RED), new Position(0, 0)), + new Pair(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); } } -- cgit v1.2.3