summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/TurnControl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/TurnControl.java')
-rw-r--r--src/jrummikub/control/TurnControl.java47
1 files changed, 41 insertions, 6 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() {