summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-05-10 01:39:35 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-05-10 01:39:35 +0200
commit201c40a399ffd238cefe1305a57f52796e21cb0a (patch)
tree9a0e1a25c298076f650ddbed45d4e5d1d973a0f8 /src/jrummikub/control
parentc9eb1cbdb8f8ffed31ac9752aa130e2bce9fa19f (diff)
downloadJRummikub-201c40a399ffd238cefe1305a57f52796e21cb0a.tar
JRummikub-201c40a399ffd238cefe1305a57f52796e21cb0a.zip
Dropping of stones on hand
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@208 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/control')
-rw-r--r--src/jrummikub/control/TurnControl.java56
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;