diff options
-rw-r--r-- | mock/jrummikub/model/MockHand.java | 11 | ||||
-rw-r--r-- | mock/jrummikub/model/MockTable.java | 5 | ||||
-rw-r--r-- | mock/jrummikub/view/MockHandPanel.java | 5 | ||||
-rw-r--r-- | src/jrummikub/model/IStoneTray.java | 2 | ||||
-rw-r--r-- | src/jrummikub/model/StoneTray.java | 4 | ||||
-rw-r--r-- | test/jrummikub/control/TurnControlTest.java | 61 |
6 files changed, 78 insertions, 10 deletions
diff --git a/mock/jrummikub/model/MockHand.java b/mock/jrummikub/model/MockHand.java index 994f7f5..f8388d0 100644 --- a/mock/jrummikub/model/MockHand.java +++ b/mock/jrummikub/model/MockHand.java @@ -1,8 +1,10 @@ package jrummikub.model; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import jrummikub.util.Pair; @@ -10,6 +12,8 @@ public class MockHand implements IHand { public List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(); + public Set<Stone> pickups = new HashSet<Stone>(); + public Iterable<Pair<Stone, Position>> iterable; @Override @@ -29,13 +33,16 @@ public class MockHand implements IHand { } @Override - public void pickUp(Stone object) { - List<Pair<Stone, Position>> itList = new ArrayList(stones); + public boolean pickUp(Stone object) { + List<Pair<Stone, Position>> itList = new ArrayList<Pair<Stone, Position>>(stones); for (Pair<Stone, Position> entry : itList) { if (entry.getFirst() == object) { stones.remove(entry); + pickups.add(object); + return true; } } + return false; } @Override diff --git a/mock/jrummikub/model/MockTable.java b/mock/jrummikub/model/MockTable.java index 0bbbe0a..f17e5df 100644 --- a/mock/jrummikub/model/MockTable.java +++ b/mock/jrummikub/model/MockTable.java @@ -43,9 +43,8 @@ public class MockTable implements ITable { } @Override - public void pickUp(StoneSet object) { - // TODO Auto-generated method stub - + public boolean pickUp(StoneSet object) { + return false; } @Override diff --git a/mock/jrummikub/view/MockHandPanel.java b/mock/jrummikub/view/MockHandPanel.java index 6069019..cb97ef7 100644 --- a/mock/jrummikub/view/MockHandPanel.java +++ b/mock/jrummikub/view/MockHandPanel.java @@ -5,6 +5,7 @@ import java.util.List; import jrummikub.model.Position; import jrummikub.model.Stone; +import jrummikub.util.Event1; import jrummikub.util.Event2; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; @@ -14,6 +15,7 @@ public class MockHandPanel implements IHandPanel { public Event2<Stone, Boolean> stoneClickEvent = new Event2<Stone, Boolean>(); public List<Pair<Stone, Position>> stones; public Event2<Stone, Boolean> rangeClickEvent = new Event2<Stone, Boolean>(); + public Event1<Position> clickEvent = new Event1<Position>(); @Override public IEvent2<Stone, Boolean> getStoneClickEvent() { @@ -33,8 +35,7 @@ public class MockHandPanel implements IHandPanel { @Override public IEvent1<Position> getClickEvent() { - // TODO Auto-generated method stub - return null; + return clickEvent; } @Override diff --git a/src/jrummikub/model/IStoneTray.java b/src/jrummikub/model/IStoneTray.java index bdf7f86..11fcbbb 100644 --- a/src/jrummikub/model/IStoneTray.java +++ b/src/jrummikub/model/IStoneTray.java @@ -33,7 +33,7 @@ public interface IStoneTray<E extends Sizeable> extends */
public Position getPosition(E object);
- public void pickUp(E object);
+ public boolean pickUp(E object);
public IStoneTray<E> clone();
diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index 8b83371..3418aec 100644 --- a/src/jrummikub/model/StoneTray.java +++ b/src/jrummikub/model/StoneTray.java @@ -217,8 +217,8 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { * @see jrummikub.model.IStoneTray#pickUp(E) */ @Override - public void pickUp(E object) { - objects.remove(object); + public boolean pickUp(E object) { + return null != objects.remove(object); } /* diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java index 44b7729..b018182 100644 --- a/test/jrummikub/control/TurnControlTest.java +++ b/test/jrummikub/control/TurnControlTest.java @@ -11,8 +11,10 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import jrummikub.model.IHand; import jrummikub.model.ITable; @@ -1026,4 +1028,63 @@ public class TurnControlTest { checkHandDisplay(mockHand); } + + @Test + public void testDropHandValid() { + testControl.startTurn(); + + Stone firstStone = new Stone(StoneColor.RED); + Stone secondStone = new Stone(StoneColor.BLACK); + + mockHand.drop(firstStone, new Position(0,0)); + mockHand.drop(secondStone, new Position(1,0)); + + mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); + mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true); + + mockView.playerPanel.handPanel.clickEvent.emit(new Position(2,0.25f)); + + assertCollection(new ArrayList<Stone>()); + + Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, secondStone)); + assertEquals(expected, mockHand.pickups); + + Set<Stone> handStones = new HashSet<Stone>(); + for (Pair<Stone, Position> stone : mockHand.stones) { + assertEquals(stone.getSecond(), new Position(2,0)); + handStones.add(stone.getFirst()); + } + assertEquals(expected, handStones); + } + + @Test + public void testDropHandInvalid() { + testControl.startTurn(); + + Stone firstStone = new Stone(StoneColor.RED); + Stone secondStone = new Stone(StoneColor.BLACK); + Stone thirdStone = new Stone(13, StoneColor.BLACK); + + mockHand.drop(firstStone, new Position(0,0)); + mockHand.drop(thirdStone, new Position(1,0)); + + mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true); + mockView.tablePanel.stoneClickEvent.emit(secondStone, true); + mockView.playerPanel.handPanel.stoneClickEvent.emit(thirdStone, true); + + mockView.playerPanel.handPanel.clickEvent.emit(new Position(2,0.25f)); + + assertCollection(Arrays.asList(secondStone)); + + Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, thirdStone)); + assertEquals(expected, mockHand.pickups); + + Set<Stone> handStones = new HashSet<Stone>(); + for (Pair<Stone, Position> stone : mockHand.stones) { + assertEquals(stone.getSecond(), new Position(2,0)); + handStones.add(stone.getFirst()); + } + assertEquals(expected, handStones); + } + } |