diff options
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r-- | src/jrummikub/control/TurnControl.java | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java index 686d923..632c3ee 100644 --- a/src/jrummikub/control/TurnControl.java +++ b/src/jrummikub/control/TurnControl.java @@ -60,8 +60,16 @@ public class TurnControl { connections.add(view.getPlayerPanel().getEndTurnEvent() .add(endOfTurnListener)); - connections.add(view.getPlayerPanel().getHandPanel().getStoneClickEvent() - .add(new IListener2<Stone, Boolean>() { + connections.add(view.getPlayerPanel().getHandPanel().getClickEvent() + .add(new IListener1<Position>() { + @Override + public void handle(Position pos) { + handClick(pos); + } + })); + + connections.add(view.getPlayerPanel().getHandPanel() + .getStoneClickEvent().add(new IListener2<Stone, Boolean>() { @Override public void handle(Stone stone, Boolean collect) { @@ -69,8 +77,8 @@ public class TurnControl { } })); - connections.add(view.getPlayerPanel().getHandPanel().getRangeClickEvent() - .add(new IListener2<Stone, Boolean>() { + connections.add(view.getPlayerPanel().getHandPanel() + .getRangeClickEvent().add(new IListener2<Stone, Boolean>() { @Override public void handle(Stone stone, Boolean collect) { @@ -161,6 +169,26 @@ public class TurnControl { timer.startTimer(); } + private void handClick(Position pos) { + List<Stone> handStones = new ArrayList<Stone>(); + for (Stone s : selectedStones) { + if (hand.pickUp(s)) { + handStones.add(s); + } + } + + int i = 0; + for (Stone s : handStones) { + float x = Math.max(0, + Math.min(13, pos.getX() - handStones.size() / 2.0f + i)); + hand.drop(s, new Position(x, (float) Math.floor(pos.getY()))); + selectedStones.remove(s); + i++; + } + view.setSelectedStones(selectedStones); + view.getPlayerPanel().getHandPanel().setStones(hand); + } + private void sortStones(Comparator<Stone> comparator) { List<Stone> stones = new ArrayList<Stone>(); for (Pair<Stone, Position> entry : hand) { @@ -171,7 +199,6 @@ public class TurnControl { } Collections.sort(stones, comparator); - int x = 0, y = 0; for (Stone stone : stones) { hand.drop(stone, new Position(x, y)); @@ -181,8 +208,9 @@ public class TurnControl { y++; if (y >= RoundControl.HAND_HEIGHT) { - throw new ArrayIndexOutOfBoundsException(); // TODO We can't handle - // this yet... + throw new ArrayIndexOutOfBoundsException(); // TODO We can't + // handle + // this yet... } } } @@ -356,15 +384,12 @@ public class TurnControl { table.drop(joinedSet, newPos); } else { StoneSet joinedSet = new StoneSet(selectedStones).join(newSet); - table.drop(joinedSet, - new Position(newPos.getX() - selectedStones.size(), newPos.getY())); + 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())); + table.drop(new StoneSet(selectedStones), new Position(pos.getX() + + (set.size() - selectedStones.size()) * 0.5f, pos.getY())); } selectedStones.clear(); @@ -459,7 +484,8 @@ public class TurnControl { static class HandStonePositionComparator implements Comparator<Pair<Stone, Position>> { @Override - public int compare(Pair<Stone, Position> pair1, Pair<Stone, Position> pair2) { + public int compare(Pair<Stone, Position> pair1, + Pair<Stone, Position> pair2) { Position pos1 = pair1.getSecond(), pos2 = pair2.getSecond(); if (pos1.getY() < pos2.getY()) { return -1; |