diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-05-09 18:53:37 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-05-09 18:53:37 +0200 |
commit | 3f8853b3e68c19af3281a6b02ce361956f406953 (patch) | |
tree | c9c92a92671835e513a4ccf17de869da2ee64fd6 /src/jrummikub/control/TurnControl.java | |
parent | f247b3666b295451da46851cfa71c5ae76b232ff (diff) | |
download | JRummikub-3f8853b3e68c19af3281a6b02ce361956f406953.tar JRummikub-3f8853b3e68c19af3281a6b02ce361956f406953.zip |
Solved conflicts
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@189 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control/TurnControl.java')
-rw-r--r-- | src/jrummikub/control/TurnControl.java | 47 |
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() { |