diff options
-rw-r--r-- | src/jrummikub/control/TurnControl.java | 47 | ||||
-rw-r--r-- | test/jrummikub/control/TurnControlTest.java | 16 |
2 files changed, 51 insertions, 12 deletions
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index 862058f..a208ede 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -1,6 +1,8 @@ package jrummikub.control; import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; import java.util.List; import jrummikub.model.IHand; @@ -108,14 +110,14 @@ public class TurnControl { .add(new IListener1<StoneSet>() { @Override public void handle(StoneSet set) { - leftConnectorClick(set); + connectorClick(set, false); } })); connections.add(view.getTablePanel().getRightConnectorClickEvent() .add(new IListener1<StoneSet>() { @Override public void handle(StoneSet set) { - rightConnectorClick(set); + connectorClick(set, true); } })); @@ -195,12 +197,45 @@ public class TurnControl { view.setSelectedStones(selectedStones); } - private void leftConnectorClick(StoneSet set) { - - } + private void connectorClick(StoneSet set, boolean right) { + List<Stone> stones = new LinkedList<Stone>(); + Position pos = table.getPosition(set); + for (Stone stone : set) { + stones.add(stone); + } + stones.removeAll(selectedStones); + if (right) { + Collections.reverse(stones); + } + pickUpSelectedStones(); + StoneSet newSet = null; + for (Stone stone : stones) { + newSet = table.findStoneSet(stone); + if (newSet != null) { + break; + } + } + if (newSet != null) { + Position newPos = table.getPosition(newSet); + table.pickUp(newSet); + if (right) { + StoneSet joinedSet = newSet.join(new StoneSet(selectedStones)); + table.drop(joinedSet, newPos); + } else { + StoneSet joinedSet = new StoneSet(selectedStones).join(newSet); + table.drop(joinedSet, new Position(newPos.getX() + - selectedStones.size(), newPos.getY())); + } + } else { + table.drop(new StoneSet(selectedStones), new Position(pos.getX() + + (set.size() - selectedStones.size()) * 0.5f, pos.getY())); + } - private void rightConnectorClick(StoneSet set) { + selectedStones.clear(); + view.getTablePanel().setStoneSets(table); + view.getPlayerPanel().getHandPanel().setStones(hand); + view.setSelectedStones(selectedStones); } private void endOfTurn() { diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java index f195fbc..97c39d0 100644 --- a/test/jrummikub/control/TurnControlTest.java +++ b/test/jrummikub/control/TurnControlTest.java @@ -552,8 +552,10 @@ public class TurnControlTest { assertSame(newSet2.get(3), blackFour); assertSame(newSet2.get(4), blackFive); // versuche, links was wegzunehmen und wieder anzuhängen - mockView.tablePanel.stoneClickEvent.emit(redOne, false); - mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, true); + mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false); + mockView.tablePanel.stoneClickEvent.emit(redOne, true); + mockView.tablePanel.leftConnectorClickEvent.emit(newSet2); + // handcheck assertEquals(0, mockHand.getSize()); // tablecheck @@ -569,8 +571,8 @@ public class TurnControlTest { assertEquals(7, newSet1.size()); // setcheck2 assertEquals(6, newSet2.size()); - assertSame(newSet2.get(0), redOne); - assertSame(newSet2.get(1), blueFour); + assertSame(newSet2.get(0), blueFour); + assertSame(newSet2.get(1), redOne); assertSame(newSet2.get(2), redThree); assertSame(newSet2.get(3), blueTwo); assertSame(newSet2.get(4), blackFour); @@ -666,8 +668,10 @@ public class TurnControlTest { assertSame(newSet2.get(3), redOne); assertSame(newSet2.get(4), redThree); // versuche, rechts was wegzunehmen und wieder anzuhängen - mockView.tablePanel.stoneClickEvent.emit(redThree, false); - mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, true); + mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false); + mockView.tablePanel.stoneClickEvent.emit(redThree, true); + mockView.tablePanel.rightConnectorClickEvent.emit(newSet2); + // handcheck assertEquals(0, mockHand.getSize()); // tablecheck |