Dropping of stones on hand
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@208 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
c9eb1cbdb8
commit
201c40a399
2 changed files with 43 additions and 17 deletions
|
@ -60,8 +60,16 @@ public class TurnControl {
|
||||||
connections.add(view.getPlayerPanel().getEndTurnEvent()
|
connections.add(view.getPlayerPanel().getEndTurnEvent()
|
||||||
.add(endOfTurnListener));
|
.add(endOfTurnListener));
|
||||||
|
|
||||||
connections.add(view.getPlayerPanel().getHandPanel().getStoneClickEvent()
|
connections.add(view.getPlayerPanel().getHandPanel().getClickEvent()
|
||||||
.add(new IListener2<Stone, Boolean>() {
|
.add(new IListener1<Position>() {
|
||||||
|
@Override
|
||||||
|
public void handle(Position pos) {
|
||||||
|
handClick(pos);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
connections.add(view.getPlayerPanel().getHandPanel()
|
||||||
|
.getStoneClickEvent().add(new IListener2<Stone, Boolean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Stone stone, Boolean collect) {
|
public void handle(Stone stone, Boolean collect) {
|
||||||
|
@ -69,8 +77,8 @@ public class TurnControl {
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
connections.add(view.getPlayerPanel().getHandPanel().getRangeClickEvent()
|
connections.add(view.getPlayerPanel().getHandPanel()
|
||||||
.add(new IListener2<Stone, Boolean>() {
|
.getRangeClickEvent().add(new IListener2<Stone, Boolean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Stone stone, Boolean collect) {
|
public void handle(Stone stone, Boolean collect) {
|
||||||
|
@ -161,6 +169,26 @@ public class TurnControl {
|
||||||
timer.startTimer();
|
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) {
|
private void sortStones(Comparator<Stone> comparator) {
|
||||||
List<Stone> stones = new ArrayList<Stone>();
|
List<Stone> stones = new ArrayList<Stone>();
|
||||||
for (Pair<Stone, Position> entry : hand) {
|
for (Pair<Stone, Position> entry : hand) {
|
||||||
|
@ -171,7 +199,6 @@ public class TurnControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(stones, comparator);
|
Collections.sort(stones, comparator);
|
||||||
|
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
for (Stone stone : stones) {
|
for (Stone stone : stones) {
|
||||||
hand.drop(stone, new Position(x, y));
|
hand.drop(stone, new Position(x, y));
|
||||||
|
@ -181,8 +208,9 @@ public class TurnControl {
|
||||||
y++;
|
y++;
|
||||||
|
|
||||||
if (y >= RoundControl.HAND_HEIGHT) {
|
if (y >= RoundControl.HAND_HEIGHT) {
|
||||||
throw new ArrayIndexOutOfBoundsException(); // TODO We can't handle
|
throw new ArrayIndexOutOfBoundsException(); // TODO We can't
|
||||||
// this yet...
|
// handle
|
||||||
|
// this yet...
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -356,15 +384,12 @@ public class TurnControl {
|
||||||
table.drop(joinedSet, newPos);
|
table.drop(joinedSet, newPos);
|
||||||
} else {
|
} else {
|
||||||
StoneSet joinedSet = new StoneSet(selectedStones).join(newSet);
|
StoneSet joinedSet = new StoneSet(selectedStones).join(newSet);
|
||||||
table.drop(joinedSet,
|
table.drop(joinedSet, new Position(newPos.getX()
|
||||||
new Position(newPos.getX() - selectedStones.size(), newPos.getY()));
|
- selectedStones.size(), newPos.getY()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
table.drop(
|
table.drop(new StoneSet(selectedStones), new Position(pos.getX()
|
||||||
new StoneSet(selectedStones),
|
+ (set.size() - selectedStones.size()) * 0.5f, pos.getY()));
|
||||||
new Position(
|
|
||||||
pos.getX() + (set.size() - selectedStones.size()) * 0.5f, pos
|
|
||||||
.getY()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedStones.clear();
|
selectedStones.clear();
|
||||||
|
@ -459,7 +484,8 @@ public class TurnControl {
|
||||||
static class HandStonePositionComparator implements
|
static class HandStonePositionComparator implements
|
||||||
Comparator<Pair<Stone, Position>> {
|
Comparator<Pair<Stone, Position>> {
|
||||||
@Override
|
@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();
|
Position pos1 = pair1.getSecond(), pos2 = pair2.getSecond();
|
||||||
if (pos1.getY() < pos2.getY()) {
|
if (pos1.getY() < pos2.getY()) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -1051,7 +1051,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
Set<Stone> handStones = new HashSet<Stone>();
|
Set<Stone> handStones = new HashSet<Stone>();
|
||||||
for (Pair<Stone, Position> stone : mockHand.stones) {
|
for (Pair<Stone, Position> stone : mockHand.stones) {
|
||||||
assertEquals(stone.getSecond(), new Position(2,0));
|
assertEquals(stone.getSecond().getY(), 0, 0.0001);
|
||||||
handStones.add(stone.getFirst());
|
handStones.add(stone.getFirst());
|
||||||
}
|
}
|
||||||
assertEquals(expected, handStones);
|
assertEquals(expected, handStones);
|
||||||
|
@ -1081,7 +1081,7 @@ public class TurnControlTest {
|
||||||
|
|
||||||
Set<Stone> handStones = new HashSet<Stone>();
|
Set<Stone> handStones = new HashSet<Stone>();
|
||||||
for (Pair<Stone, Position> stone : mockHand.stones) {
|
for (Pair<Stone, Position> stone : mockHand.stones) {
|
||||||
assertEquals(stone.getSecond(), new Position(2,0));
|
assertEquals(stone.getSecond().getY(), 0, 0.0001);
|
||||||
handStones.add(stone.getFirst());
|
handStones.add(stone.getFirst());
|
||||||
}
|
}
|
||||||
assertEquals(expected, handStones);
|
assertEquals(expected, handStones);
|
||||||
|
|
Reference in a new issue