summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-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
4 files changed, 64 insertions, 30 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