summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mock/jrummikub/view/MockPlayerPanel.java8
-rw-r--r--mock/jrummikub/view/MockView.java8
-rw-r--r--src/jrummikub/control/TurnControl.java18
-rw-r--r--src/jrummikub/view/IPlayerPanel.java5
-rw-r--r--src/jrummikub/view/IView.java5
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java3
-rw-r--r--src/jrummikub/view/impl/View.java6
-rw-r--r--test/jrummikub/control/TurnControlTest.java100
8 files changed, 81 insertions, 72 deletions
diff --git a/mock/jrummikub/view/MockPlayerPanel.java b/mock/jrummikub/view/MockPlayerPanel.java
index f193fa1..13dbb57 100644
--- a/mock/jrummikub/view/MockPlayerPanel.java
+++ b/mock/jrummikub/view/MockPlayerPanel.java
@@ -10,19 +10,11 @@ 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() {
- // TODO Auto-generated method stub
- return handPanel;
- }
-
- @Override
public void setTimeLeft(int time) {
// TODO Auto-generated method stub
diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java
index f0337f3..1f8c9a8 100644
--- a/mock/jrummikub/view/MockView.java
+++ b/mock/jrummikub/view/MockView.java
@@ -5,6 +5,7 @@ import java.util.Collection;
import jrummikub.model.Stone;
import jrummikub.util.IEvent;
import jrummikub.util.MockEvent;
+
/**
* Mock class for View
*/
@@ -13,6 +14,8 @@ public class MockView implements IView {
public MockPlayerPanel playerPanel = new MockPlayerPanel();
/** */
public MockTablePanel tablePanel = new MockTablePanel();
+ /** */
+ public MockHandPanel handPanel = new MockHandPanel();
/** */
public Collection<Stone> selectedStones;
@@ -42,6 +45,11 @@ public class MockView implements IView {
}
@Override
+ public MockHandPanel getHandPanel() {
+ return handPanel;
+ }
+
+ @Override
public void setCurrentPlayerName(String playerName) {
currentPlayerName = playerName;
}
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java
index 4652ea7..4140b57 100644
--- a/src/jrummikub/control/TurnControl.java
+++ b/src/jrummikub/control/TurnControl.java
@@ -98,15 +98,15 @@ public class TurnControl {
}
}));
- view.getPlayerPanel().getHandPanel().setStones(hand.clone());
- view.getPlayerPanel().getHandPanel().resetCurrentRow();
+ view.getHandPanel().setStones(hand.clone());
+ view.getHandPanel().resetCurrentRow();
view.enableStartTurnPanel(false);
timer.startTimer();
}
private void addHandPanelHandlers() {
- connections.add(view.getPlayerPanel().getHandPanel().getClickEvent()
+ connections.add(view.getHandPanel().getClickEvent()
.add(new IListener1<Position>() {
@Override
public void handle(Position pos) {
@@ -114,7 +114,7 @@ public class TurnControl {
}
}));
- connections.add(view.getPlayerPanel().getHandPanel().getStoneClickEvent()
+ connections.add(view.getHandPanel().getStoneClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
@@ -123,7 +123,7 @@ public class TurnControl {
}
}));
- connections.add(view.getPlayerPanel().getHandPanel().getRangeClickEvent()
+ connections.add(view.getHandPanel().getRangeClickEvent()
.add(new IListener2<Stone, Boolean>() {
@Override
@@ -227,7 +227,7 @@ public class TurnControl {
i++;
}
view.setSelectedStones(selectedStones);
- view.getPlayerPanel().getHandPanel().setStones(hand);
+ view.getHandPanel().setStones(hand);
}
private void sortStones(Comparator<Stone> comparator) {
@@ -250,7 +250,7 @@ public class TurnControl {
}
}
- view.getPlayerPanel().getHandPanel().setStones(hand);
+ view.getHandPanel().setStones(hand);
}
private void sortByRuns() {
@@ -307,7 +307,7 @@ public class TurnControl {
selectedStones.clear();
view.getTablePanel().setStoneSets(table);
- view.getPlayerPanel().getHandPanel().setStones(hand);
+ view.getHandPanel().setStones(hand);
view.setSelectedStones(selectedStones);
}
@@ -433,7 +433,7 @@ public class TurnControl {
selectedStones.clear();
view.getTablePanel().setStoneSets(table);
- view.getPlayerPanel().getHandPanel().setStones(hand);
+ view.getHandPanel().setStones(hand);
view.setSelectedStones(selectedStones);
}
diff --git a/src/jrummikub/view/IPlayerPanel.java b/src/jrummikub/view/IPlayerPanel.java
index 86c1440..3fb8709 100644
--- a/src/jrummikub/view/IPlayerPanel.java
+++ b/src/jrummikub/view/IPlayerPanel.java
@@ -7,11 +7,6 @@ import jrummikub.util.IEvent;
*/
public interface IPlayerPanel {
/**
- * @return the board where the players hand stones are displayed
- */
- public IHandPanel getHandPanel();
-
- /**
* Sets the time the player has left for his turn
*
* @param time
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index d69d942..5828edd 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -17,6 +17,11 @@ public interface IView {
public ITablePanel getTablePanel();
/**
+ * @return the board where the players hand stones are displayed
+ */
+ public IHandPanel getHandPanel();
+
+ /**
* Returns the player panel
*
* @return the playerPanel
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index 20fb05a..8d0719a 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -49,8 +49,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private Event sortByRunsEvent = new Event();
private Event endTurnEvent = new Event();
- @Override
- public HandPanel getHandPanel() {
+ HandPanel getHandPanel() {
return hand;
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 869f4cd..9290b60 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -11,6 +11,7 @@ import javax.swing.border.MatteBorder;
import jrummikub.model.Stone;
import jrummikub.util.IEvent;
+import jrummikub.view.IHandPanel;
import jrummikub.view.IPlayerPanel;
import jrummikub.view.ITablePanel;
import jrummikub.view.IView;
@@ -39,6 +40,11 @@ public class View extends JFrame implements IView {
}
@Override
+ public IHandPanel getHandPanel() {
+ return playerPanel.getHandPanel();
+ }
+
+ @Override
public IPlayerPanel getPlayerPanel() {
return playerPanel;
}
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/TurnControlTest.java
index 15b6937..edace0a 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/TurnControlTest.java
@@ -85,7 +85,7 @@ public class TurnControlTest {
}
private void checkHandDisplay(IHand hand) {
- Iterator<Pair<Stone, Position>> stoneSetsView = mockView.playerPanel.handPanel.stones
+ Iterator<Pair<Stone, Position>> stoneSetsView = mockView.handPanel.stones
.iterator();
Iterator<Pair<Stone, Position>> stoneSetsModel = hand.iterator();
@@ -131,7 +131,7 @@ public class TurnControlTest {
testControl.startTurn();
int i = 0;
- for (Pair<Stone, Position> pair : mockView.playerPanel.handPanel.stones) {
+ for (Pair<Stone, Position> pair : mockView.handPanel.stones) {
assertSame(stones.get(i), pair);
i++;
}
@@ -193,7 +193,7 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, false);
+ mockView.handPanel.stoneClickEvent.emit(firstStone, false);
mockTimer.timeRunOutEvent.emit();
assertCollection(new ArrayList<Stone>());
@@ -207,13 +207,13 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, false);
+ mockView.handPanel.stoneClickEvent.emit(firstStone, false);
assertCollection(Arrays.asList(firstStone));
// Select second stone
Stone secondStone = new Stone(StoneColor.BLACK);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, false);
+ mockView.handPanel.stoneClickEvent.emit(secondStone, false);
assertCollection(Arrays.asList(secondStone));
@@ -227,18 +227,18 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
// Select first stone
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
+ mockView.handPanel.stoneClickEvent.emit(firstStone, true);
assertCollection(Arrays.asList(firstStone));
// Select second stone
Stone secondStone = new Stone(StoneColor.BLACK);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
+ mockView.handPanel.stoneClickEvent.emit(secondStone, true);
assertCollection(Arrays.asList(firstStone, secondStone));
// De-select first stone
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
+ mockView.handPanel.stoneClickEvent.emit(firstStone, true);
assertCollection(Arrays.asList(secondStone));
}
@@ -251,8 +251,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
+ mockView.handPanel.stoneClickEvent.emit(firstStone, true);
+ mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
false);
@@ -268,8 +268,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
+ mockView.handPanel.stoneClickEvent.emit(firstStone, true);
+ mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
true);
@@ -285,8 +285,8 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
+ mockView.handPanel.stoneClickEvent.emit(firstStone, true);
+ mockView.handPanel.stoneClickEvent.emit(secondStone, true);
mockView.tablePanel.stoneCollectionPanel.stoneClickEvent.emit(firstStone,
true);
@@ -516,8 +516,8 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1));
- mockView.playerPanel.handPanel.stoneClickEvent.emit(stone3, false);
- mockView.playerPanel.handPanel.rangeClickEvent.emit(stone1, true);
+ mockView.handPanel.stoneClickEvent.emit(stone3, false);
+ mockView.handPanel.rangeClickEvent.emit(stone1, true);
assertCollection(Arrays.asList(stone1, stone2, stone3));
}
@@ -536,8 +536,8 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1));
- mockView.playerPanel.handPanel.stoneClickEvent.emit(stone1, false);
- mockView.playerPanel.handPanel.rangeClickEvent.emit(stone3, true);
+ mockView.handPanel.stoneClickEvent.emit(stone1, false);
+ mockView.handPanel.rangeClickEvent.emit(stone3, true);
assertCollection(Arrays.asList(stone1, stone2, stone3));
}
@@ -558,10 +558,10 @@ public class TurnControlTest {
mockHand.drop(stone3, new Position(0, 1));
mockHand.drop(stone4, new Position(1, 1));
- mockView.playerPanel.handPanel.stoneClickEvent.emit(extraStone, false);
+ mockView.handPanel.stoneClickEvent.emit(extraStone, false);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(stone1, true);
- mockView.playerPanel.handPanel.rangeClickEvent.emit(stone3, false);
+ mockView.handPanel.stoneClickEvent.emit(stone1, true);
+ mockView.handPanel.rangeClickEvent.emit(stone3, false);
assertCollection(Arrays.asList(extraStone, stone1, stone2, stone3));
}
@@ -581,7 +581,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(stone1));
// Select second stone
- mockView.playerPanel.handPanel.rangeClickEvent.emit(stone2, false);
+ mockView.handPanel.rangeClickEvent.emit(stone2, false);
assertCollection(Arrays.asList(stone1, stone2));
@@ -603,7 +603,7 @@ public class TurnControlTest {
assertCollection(Arrays.asList(stone1));
// Select second stone
- mockView.playerPanel.handPanel.rangeClickEvent.emit(stone2, true);
+ mockView.handPanel.rangeClickEvent.emit(stone2, true);
assertCollection(Arrays.asList(stone1, stone2));
}
@@ -643,7 +643,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0));
- mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false);
+ mockView.handPanel.stoneClickEvent.emit(blueThree, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.leftConnectorClickEvent.emit(oldSet1);
@@ -705,7 +705,7 @@ public class TurnControlTest {
assertSame(newSet2.get(3), blackFour);
assertSame(newSet2.get(4), blackFive);
// versuche, links was wegzunehmen und wieder anzuhängen
- mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false);
+ mockView.handPanel.stoneClickEvent.emit(blueFour, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.leftConnectorClickEvent.emit(newSet2);
@@ -760,7 +760,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0));
- mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false);
+ mockView.handPanel.stoneClickEvent.emit(blueThree, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.rightConnectorClickEvent.emit(oldSet1);
@@ -822,7 +822,7 @@ public class TurnControlTest {
assertSame(newSet2.get(3), redOne);
assertSame(newSet2.get(4), redThree);
// versuche, rechts was wegzunehmen und wieder anzuhängen
- mockView.playerPanel.handPanel.stoneClickEvent.emit(blueFour, false);
+ mockView.handPanel.stoneClickEvent.emit(blueFour, false);
mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.rightConnectorClickEvent.emit(newSet2);
@@ -877,7 +877,7 @@ public class TurnControlTest {
table.drop(oldSet2, new Position(0, 0));
mockHand.drop(blueThree, new Position(0, 0));
mockHand.drop(blueFour, new Position(0, 0));
- mockView.playerPanel.handPanel.stoneClickEvent.emit(blueThree, false);
+ mockView.handPanel.stoneClickEvent.emit(blueThree, false);
mockView.tablePanel.stoneClickEvent.emit(redOne, true);
mockView.tablePanel.stoneClickEvent.emit(redThree, true);
mockView.tablePanel.stoneClickEvent.emit(blueTwo, true);
@@ -939,6 +939,7 @@ public class TurnControlTest {
checkTableDisplay(table);
checkHandDisplay(mockHand);
}
+
/** */
@Test
public void testSortByGroups() {
@@ -1060,7 +1061,7 @@ public class TurnControlTest {
checkHandDisplay(mockHand);
}
-
+
/** */
@Test
public void testDropHandValid() {
@@ -1068,20 +1069,21 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
-
- mockHand.drop(firstStone, new Position(0,0));
- mockHand.drop(secondStone, new Position(1,0));
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(secondStone, true);
+ mockHand.drop(firstStone, new Position(0, 0));
+ mockHand.drop(secondStone, new Position(1, 0));
+
+ mockView.handPanel.stoneClickEvent.emit(firstStone, true);
+ mockView.handPanel.stoneClickEvent.emit(secondStone, true);
- mockView.playerPanel.handPanel.clickEvent.emit(new Position(2,0.25f));
+ mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
assertCollection(new ArrayList<Stone>());
-
- Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, secondStone));
+
+ Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone,
+ secondStone));
assertEquals(expected, mockHand.pickups);
-
+
Set<Stone> handStones = new HashSet<Stone>();
for (Pair<Stone, Position> stone : mockHand.stones) {
assertEquals(stone.getSecond().getY(), 0, 0.0001);
@@ -1089,6 +1091,7 @@ public class TurnControlTest {
}
assertEquals(expected, handStones);
}
+
/** */
@Test
public void testDropHandInvalid() {
@@ -1097,21 +1100,22 @@ public class TurnControlTest {
Stone firstStone = new Stone(StoneColor.RED);
Stone secondStone = new Stone(StoneColor.BLACK);
Stone thirdStone = new Stone(13, StoneColor.BLACK);
-
- mockHand.drop(firstStone, new Position(0,0));
- mockHand.drop(thirdStone, new Position(1,0));
- mockView.playerPanel.handPanel.stoneClickEvent.emit(firstStone, true);
+ mockHand.drop(firstStone, new Position(0, 0));
+ mockHand.drop(thirdStone, new Position(1, 0));
+
+ mockView.handPanel.stoneClickEvent.emit(firstStone, true);
mockView.tablePanel.stoneClickEvent.emit(secondStone, true);
- mockView.playerPanel.handPanel.stoneClickEvent.emit(thirdStone, true);
+ mockView.handPanel.stoneClickEvent.emit(thirdStone, true);
- mockView.playerPanel.handPanel.clickEvent.emit(new Position(2,0.25f));
+ mockView.handPanel.clickEvent.emit(new Position(2, 0.25f));
assertCollection(Arrays.asList(secondStone));
-
- Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone, thirdStone));
+
+ Set<Stone> expected = new HashSet<Stone>(Arrays.asList(firstStone,
+ thirdStone));
assertEquals(expected, mockHand.pickups);
-
+
Set<Stone> handStones = new HashSet<Stone>();
for (Pair<Stone, Position> stone : mockHand.stones) {
assertEquals(stone.getSecond().getY(), 0, 0.0001);
@@ -1119,5 +1123,5 @@ public class TurnControlTest {
}
assertEquals(expected, handStones);
}
-
+
}