summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mock/jrummikub/view/MockPlayerPanel.java8
-rw-r--r--src/jrummikub/control/TurnControl.java25
-rw-r--r--test/jrummikub/control/TurnControlTest.java107
3 files changed, 130 insertions, 10 deletions
diff --git a/mock/jrummikub/view/MockPlayerPanel.java b/mock/jrummikub/view/MockPlayerPanel.java
index fcf560e..8103c7e 100644
--- a/mock/jrummikub/view/MockPlayerPanel.java
+++ b/mock/jrummikub/view/MockPlayerPanel.java
@@ -6,6 +6,8 @@ import jrummikub.util.MockEvent;
public class MockPlayerPanel implements IPlayerPanel {
public MockEvent endTurnEvent = new MockEvent();
public MockHandPanel handPanel = new MockHandPanel();
+ public MockEvent sortByGroupsEvent = new MockEvent();
+ public MockEvent sortByRunsEvent = new MockEvent();
@Override
public IHandPanel getHandPanel() {
@@ -21,14 +23,12 @@ public class MockPlayerPanel implements IPlayerPanel {
@Override
public IEvent getSortByGroupsEvent() {
- // TODO Auto-generated method stub
- return null;
+ return sortByGroupsEvent;
}
@Override
public IEvent getSortByRunsEvent() {
- // TODO Auto-generated method stub
- return null;
+ return sortByRunsEvent;
}
@Override
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java
index bf921e4..e82b30f 100644
--- a/src/jrummikub/control/TurnControl.java
+++ b/src/jrummikub/control/TurnControl.java
@@ -21,7 +21,7 @@ import jrummikub.util.Pair;
import jrummikub.view.IView;
public class TurnControl {
- private static class HandStoneComparator implements
+ static class HandStonePositionComparator implements
Comparator<Pair<Stone, Position>> {
@Override
public int compare(Pair<Stone, Position> pair1,
@@ -161,6 +161,20 @@ public class TurnControl {
connectorClick(set, true);
}
}));
+ connections.add(view.getPlayerPanel().getSortByGroupsEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ sortByGroups();
+ }
+ }));
+ connections.add(view.getPlayerPanel().getSortByRunsEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ sortByRuns();
+ }
+ }));
view.getPlayerPanel().getHandPanel().setStones(hand.clone());
view.enableStartTurnPanel(false);
@@ -168,11 +182,11 @@ public class TurnControl {
timer.startTimer();
}
- private void sortByValue() {
+ private void sortByRuns() {
}
- private void sortByColor() {
+ private void sortByGroups() {
}
@@ -286,7 +300,7 @@ public class TurnControl {
handPairs.add(entry);
}
- Collections.sort(handPairs, new HandStoneComparator());
+ Collections.sort(handPairs, new HandStonePositionComparator());
List<Stone> handStones = new ArrayList<Stone>();
for (Pair<Stone, Position> entry : handPairs) {
@@ -338,8 +352,7 @@ public class TurnControl {
- 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(RoundControl.HAND_WIDTH-1, RoundControl.HAND_HEIGHT-1));
}
selectedStones.clear();
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
index fdc43fc..b4766b6 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -10,6 +10,7 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -909,4 +910,110 @@ public class TurnControlTest {
checkTableDisplay(table);
checkHandDisplay(mockHand);
}
+
+ @Test
+ public void testSortByGroups() {
+ Stone red1 = new Stone(1, StoneColor.RED);
+ Stone blue2 = new Stone(2, StoneColor.BLUE);
+ Stone red4 = new Stone(4, StoneColor.RED);
+ Stone red3 = new Stone(3, StoneColor.RED);
+ Stone orange10 = new Stone(10, StoneColor.ORANGE);
+ Stone blue1 = new Stone(1, StoneColor.BLUE);
+ Stone blue4 = new Stone(4, StoneColor.BLUE);
+ Stone blue4a = new Stone(4, StoneColor.BLUE);
+ Stone joker = new Stone(StoneColor.BLACK);
+ Stone black5 = new Stone(5, StoneColor.BLACK);
+ Stone orange13 = new Stone(13, StoneColor.ORANGE);
+ Stone red11 = new Stone(11, StoneColor.RED);
+ Stone black10 = new Stone(10, StoneColor.BLACK);
+ mockHand.drop(red1, new Position(0, 0));
+ mockHand.drop(blue2, new Position(0, 0));
+ mockHand.drop(red4, new Position(0, 0));
+ mockHand.drop(red3, new Position(0, 0));
+ mockHand.drop(orange10, new Position(0, 0));
+ mockHand.drop(blue1, new Position(0, 0));
+ mockHand.drop(blue4, new Position(0, 0));
+ mockHand.drop(blue4a, new Position(0, 0));
+ mockHand.drop(joker, new Position(0, 0));
+ mockHand.drop(black5, new Position(0, 0));
+ mockHand.drop(orange13, new Position(0, 0));
+ mockHand.drop(red11, new Position(0, 0));
+ mockHand.drop(black10, new Position(0, 0));
+
+ mockView.playerPanel.sortByGroupsEvent.emit();
+
+ List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(mockHand.stones);
+ Collections.sort(stones, new TurnControl.HandStonePositionComparator());
+
+ assertEquals(stones.size(), 13);
+
+ assertSame(stones.get(0).getFirst(), blue1);
+ assertSame(stones.get(1).getFirst(), red1);
+ assertSame(stones.get(2).getFirst(), blue2);
+ assertSame(stones.get(3).getFirst(), red3);
+
+ assertTrue(stones.get(4).getFirst() == blue4 || stones.get(4).getFirst() == blue4a);
+ assertTrue(stones.get(5).getFirst() == blue4 || stones.get(5).getFirst() == blue4a);
+
+ assertSame(stones.get(6).getFirst(), red4);
+ assertSame(stones.get(7).getFirst(), black5);
+ assertSame(stones.get(8).getFirst(), black10);
+ assertSame(stones.get(9).getFirst(), orange10);
+ assertSame(stones.get(10).getFirst(), red11);
+ assertSame(stones.get(11).getFirst(), orange13);
+ assertSame(stones.get(12).getFirst(), joker);
+ }
+
+ @Test
+ public void testSortByRuns() {
+ Stone red1 = new Stone(1, StoneColor.RED);
+ Stone blue2 = new Stone(2, StoneColor.BLUE);
+ Stone red4 = new Stone(4, StoneColor.RED);
+ Stone red3 = new Stone(3, StoneColor.RED);
+ Stone orange10 = new Stone(10, StoneColor.ORANGE);
+ Stone blue1 = new Stone(1, StoneColor.BLUE);
+ Stone blue4 = new Stone(4, StoneColor.BLUE);
+ Stone blue4a = new Stone(4, StoneColor.BLUE);
+ Stone joker = new Stone(StoneColor.BLACK);
+ Stone black5 = new Stone(5, StoneColor.BLACK);
+ Stone orange13 = new Stone(13, StoneColor.ORANGE);
+ Stone red11 = new Stone(11, StoneColor.RED);
+ Stone black10 = new Stone(10, StoneColor.BLACK);
+ mockHand.drop(red1, new Position(0, 0));
+ mockHand.drop(blue2, new Position(0, 0));
+ mockHand.drop(red4, new Position(0, 0));
+ mockHand.drop(red3, new Position(0, 0));
+ mockHand.drop(orange10, new Position(0, 0));
+ mockHand.drop(blue1, new Position(0, 0));
+ mockHand.drop(blue4, new Position(0, 0));
+ mockHand.drop(blue4a, new Position(0, 0));
+ mockHand.drop(joker, new Position(0, 0));
+ mockHand.drop(black5, new Position(0, 0));
+ mockHand.drop(orange13, new Position(0, 0));
+ mockHand.drop(red11, new Position(0, 0));
+ mockHand.drop(black10, new Position(0, 0));
+
+ mockView.playerPanel.sortByRunsEvent.emit();
+
+ List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(mockHand.stones);
+ Collections.sort(stones, new TurnControl.HandStonePositionComparator());
+
+ assertEquals(stones.size(), 13);
+
+ assertSame(stones.get(0).getFirst(), black5);
+ assertSame(stones.get(1).getFirst(), black10);
+ assertSame(stones.get(2).getFirst(), orange10);
+ assertSame(stones.get(3).getFirst(), orange13);
+ assertSame(stones.get(4).getFirst(), blue1);
+ assertSame(stones.get(5).getFirst(), blue2);
+
+ assertTrue(stones.get(6).getFirst() == blue4 || stones.get(6).getFirst() == blue4a);
+ assertTrue(stones.get(7).getFirst() == blue4 || stones.get(7).getFirst() == blue4a);
+
+ assertSame(stones.get(8).getFirst(), red1);
+ assertSame(stones.get(9).getFirst(), red3);
+ assertSame(stones.get(10).getFirst(), red4);
+ assertSame(stones.get(11).getFirst(), red11);
+ assertSame(stones.get(12).getFirst(), joker);
+ }
}