summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jrummikub/control/RoundControl.java4
-rw-r--r--src/jrummikub/control/turn/AbstractTurnControl.java27
-rw-r--r--src/jrummikub/control/turn/HumanTurnControl.java (renamed from src/jrummikub/control/TurnControl.java)36
-rw-r--r--src/jrummikub/control/turn/ITurnControl.java27
-rw-r--r--test/jrummikub/control/turn/TurnControlTest.java (renamed from test/jrummikub/control/TurnControlTest.java)22
5 files changed, 76 insertions, 40 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 3bb1a3b..e507e74 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -5,6 +5,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import jrummikub.control.turn.HumanTurnControl;
+import jrummikub.control.turn.ITurnControl;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
import jrummikub.model.IPlayer;
@@ -93,7 +95,7 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
- TurnControl turnControl = new TurnControl(roundState.getActivePlayer()
+ ITurnControl turnControl = new HumanTurnControl(roundState.getActivePlayer()
.getHand(), clonedTable, view, inspectOnly);
turnControl.getEndOfTurnEvent().add(new IListener() {
diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java
new file mode 100644
index 0000000..9e3b069
--- /dev/null
+++ b/src/jrummikub/control/turn/AbstractTurnControl.java
@@ -0,0 +1,27 @@
+package jrummikub.control.turn;
+
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
+
+/**
+ * Abstract base class for TurnControls
+ */
+public abstract class AbstractTurnControl implements ITurnControl {
+
+ protected Event endOfTurnEvent = new Event();
+ protected Event redealEvent = new Event();
+
+ @Override
+ public abstract void startTurn();
+
+ @Override
+ public IEvent getEndOfTurnEvent() {
+ return endOfTurnEvent;
+ }
+
+ @Override
+ public Event getRedealEvent() {
+ return redealEvent;
+ }
+
+} \ No newline at end of file
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java
index 1488c75..9b44f4e 100644
--- a/src/jrummikub/control/TurnControl.java
+++ b/src/jrummikub/control/turn/HumanTurnControl.java
@@ -1,4 +1,4 @@
-package jrummikub.control;
+package jrummikub.control.turn;
import java.util.ArrayList;
import java.util.Collections;
@@ -6,6 +6,8 @@ import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
+import jrummikub.control.ITurnTimer;
+import jrummikub.control.TurnTimer;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
import jrummikub.model.ITable;
@@ -14,8 +16,6 @@ import jrummikub.model.Stone;
import jrummikub.model.StoneColor;
import jrummikub.model.StoneSet;
import jrummikub.util.Connection;
-import jrummikub.util.Event;
-import jrummikub.util.IEvent;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.util.IListener2;
@@ -25,7 +25,7 @@ import jrummikub.view.IView;
/**
* Controller for a single turn made by a human player
*/
-public class TurnControl {
+public class HumanTurnControl extends AbstractTurnControl {
private IHand hand;
private ITable table;
private ITurnTimer timer;
@@ -33,8 +33,6 @@ public class TurnControl {
private List<Stone> selectedStones = new ArrayList<Stone>();
- private Event endOfTurnEvent = new Event();
- private Event redealEvent = new Event();
private List<Connection> connections = new ArrayList<Connection>();
private boolean inspectOnly;
@@ -52,7 +50,7 @@ public class TurnControl {
* @param inspectOnly
* the current turn doesn't allow any table manipulation
*/
- public TurnControl(IHand hand, ITable table, IView view, boolean inspectOnly) {
+ public HumanTurnControl(IHand hand, ITable table, IView view, boolean inspectOnly) {
this.hand = hand;
this.table = table;
this.view = view;
@@ -61,7 +59,7 @@ public class TurnControl {
}
/** Test only constructor **/
- TurnControl(IHand hand, ITable table, IView view, ITurnTimer testTimer) {
+ HumanTurnControl(IHand hand, ITable table, IView view, ITurnTimer testTimer) {
this.hand = hand;
this.table = table;
this.view = view;
@@ -69,9 +67,7 @@ public class TurnControl {
this.inspectOnly = false;
}
- /**
- * Start the turn
- */
+ @Override
public void startTurn() {
IListener endOfTurnListener = new IListener() {
@@ -462,15 +458,6 @@ public class TurnControl {
view.setSelectedStones(new ArrayList<Stone>());
}
- /**
- * Get the event that is emitted when the turn is over
- *
- * @return end of turn event
- */
- public IEvent getEndOfTurnEvent() {
- return endOfTurnEvent;
- }
-
static private int compareJokers(Stone s1, Stone s2) {
if (!s1.isJoker() && s2.isJoker()) {
return -1;
@@ -561,14 +548,5 @@ public class TurnControl {
}
}
}
-
- /**
- * Emitted when the round is aborted and needs to be restarted
- *
- * @return the event
- */
- public Event getRedealEvent() {
- return redealEvent;
- }
}
diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java
new file mode 100644
index 0000000..8c80b1f
--- /dev/null
+++ b/src/jrummikub/control/turn/ITurnControl.java
@@ -0,0 +1,27 @@
+package jrummikub.control.turn;
+
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
+
+public interface ITurnControl {
+
+ /**
+ * Start the turn
+ */
+ public abstract void startTurn();
+
+ /**
+ * Get the event that is emitted when the turn is over
+ *
+ * @return end of turn event
+ */
+ public abstract IEvent getEndOfTurnEvent();
+
+ /**
+ * Emitted when the round is aborted and needs to be restarted
+ *
+ * @return the event
+ */
+ public abstract Event getRedealEvent();
+
+} \ No newline at end of file
diff --git a/test/jrummikub/control/TurnControlTest.java b/test/jrummikub/control/turn/TurnControlTest.java
index edace0a..150f3e9 100644
--- a/test/jrummikub/control/TurnControlTest.java
+++ b/test/jrummikub/control/turn/TurnControlTest.java
@@ -1,4 +1,4 @@
-package jrummikub.control;
+package jrummikub.control.turn;
import static jrummikub.model.StoneColor.BLACK;
import static jrummikub.model.StoneColor.BLUE;
@@ -16,6 +16,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import jrummikub.control.ITurnTimer;
+import jrummikub.control.turn.HumanTurnControl;
import jrummikub.model.IHand;
import jrummikub.model.ITable;
import jrummikub.model.MockHand;
@@ -35,7 +37,7 @@ import org.junit.Before;
import org.junit.Test;
/**
- * Tests for {@link TurnControl}
+ * Tests for {@link HumanTurnControl}
*/
public class TurnControlTest {
static class AccessibleTable extends Table {
@@ -65,7 +67,7 @@ public class TurnControlTest {
}
- TurnControl testControl;
+ HumanTurnControl testControl;
MockView mockView;
MockTimer mockTimer;
MockTable mockTable;
@@ -103,7 +105,7 @@ public class TurnControlTest {
mockTimer = new MockTimer();
mockTable = new MockTable();
mockHand = new MockHand();
- testControl = new TurnControl(mockHand, mockTable, mockView, mockTimer);
+ testControl = new HumanTurnControl(mockHand, mockTable, mockView, mockTimer);
}
/** */
@@ -126,7 +128,7 @@ public class TurnControlTest {
mockHand.iterable = stones;
- testControl = new TurnControl(mockHand, mockTable, mockView, mockTimer);
+ testControl = new HumanTurnControl(mockHand, mockTable, mockView, mockTimer);
testControl.startTurn();
@@ -619,7 +621,7 @@ public class TurnControlTest {
@Test
public void testAddLeft() {
AccessibleTable table = new AccessibleTable();
- TurnControl turnControl = new TurnControl(mockHand, table, mockView,
+ HumanTurnControl turnControl = new HumanTurnControl(mockHand, table, mockView,
mockTimer);
turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
@@ -736,7 +738,7 @@ public class TurnControlTest {
@Test
public void testAddRight() {
AccessibleTable table = new AccessibleTable();
- TurnControl turnControl = new TurnControl(mockHand, table, mockView,
+ HumanTurnControl turnControl = new HumanTurnControl(mockHand, table, mockView,
mockTimer);
turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
@@ -853,7 +855,7 @@ public class TurnControlTest {
@Test
public void testAddNewSet() {
AccessibleTable table = new AccessibleTable();
- TurnControl turnControl = new TurnControl(mockHand, table, mockView,
+ HumanTurnControl turnControl = new HumanTurnControl(mockHand, table, mockView,
mockTimer);
turnControl.startTurn();
Stone blueOne = new Stone(1, BLUE);
@@ -976,7 +978,7 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones);
- Collections.sort(stones, new TurnControl.HandStonePositionComparator());
+ Collections.sort(stones, new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13);
@@ -1037,7 +1039,7 @@ public class TurnControlTest {
List<Pair<Stone, Position>> stones = new ArrayList<Pair<Stone, Position>>(
mockHand.stones);
- Collections.sort(stones, new TurnControl.HandStonePositionComparator());
+ Collections.sort(stones, new HumanTurnControl.HandStonePositionComparator());
assertEquals(stones.size(), 13);