From 201c40a399ffd238cefe1305a57f52796e21cb0a Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Tue, 10 May 2011 01:39:35 +0200 Subject: Dropping of stones on hand git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@208 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/TurnControl.java | 56 +++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 15 deletions(-) (limited to 'src/jrummikub') 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() { + connections.add(view.getPlayerPanel().getHandPanel().getClickEvent() + .add(new IListener1() { + @Override + public void handle(Position pos) { + handClick(pos); + } + })); + + connections.add(view.getPlayerPanel().getHandPanel() + .getStoneClickEvent().add(new IListener2() { @Override public void handle(Stone stone, Boolean collect) { @@ -69,8 +77,8 @@ public class TurnControl { } })); - connections.add(view.getPlayerPanel().getHandPanel().getRangeClickEvent() - .add(new IListener2() { + connections.add(view.getPlayerPanel().getHandPanel() + .getRangeClickEvent().add(new IListener2() { @Override public void handle(Stone stone, Boolean collect) { @@ -161,6 +169,26 @@ public class TurnControl { timer.startTimer(); } + private void handClick(Position pos) { + List handStones = new ArrayList(); + 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 comparator) { List stones = new ArrayList(); for (Pair 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> { @Override - public int compare(Pair pair1, Pair pair2) { + public int compare(Pair pair1, + Pair pair2) { Position pos1 = pair1.getSecond(), pos2 = pair2.getSecond(); if (pos1.getY() < pos2.getY()) { return -1; -- cgit v1.2.3