summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-05-29 19:46:53 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-05-29 19:46:53 +0200
commiteb7ccb46c5023fb8a3052f1c6d9fa5d2e384d15e (patch)
tree85105d196afe72c2df3cae32ebc4f8b59e85da91 /src/jrummikub
parent73f6fb9c1b12e70896ee431af326bef0a7235b4f (diff)
downloadJRummikub-eb7ccb46c5023fb8a3052f1c6d9fa5d2e384d15e.tar
JRummikub-eb7ccb46c5023fb8a3052f1c6d9fa5d2e384d15e.zip
Added TurnControlFactory
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@308 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/RoundControl.java8
-rw-r--r--src/jrummikub/control/turn/HumanTurnControl.java35
-rw-r--r--src/jrummikub/control/turn/TurnControlFactory.java9
-rw-r--r--src/jrummikub/model/PlayerSettings.java49
4 files changed, 86 insertions, 15 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index e507e74..671086f 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -95,8 +95,12 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
- ITurnControl turnControl = new HumanTurnControl(roundState.getActivePlayer()
- .getHand(), clonedTable, view, inspectOnly);
+ ITurnControl turnControl = roundState
+ .getActivePlayer()
+ .getPlayerSettings()
+ .getTurnControlFactory()
+ .create(roundState.getActivePlayer().getHand(), clonedTable,
+ view, inspectOnly);
turnControl.getEndOfTurnEvent().add(new IListener() {
@Override
diff --git a/src/jrummikub/control/turn/HumanTurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java
index 9b44f4e..399f547 100644
--- a/src/jrummikub/control/turn/HumanTurnControl.java
+++ b/src/jrummikub/control/turn/HumanTurnControl.java
@@ -34,7 +34,7 @@ public class HumanTurnControl extends AbstractTurnControl {
private List<Stone> selectedStones = new ArrayList<Stone>();
private List<Connection> connections = new ArrayList<Connection>();
-
+
private boolean inspectOnly;
/**
@@ -50,7 +50,8 @@ public class HumanTurnControl extends AbstractTurnControl {
* @param inspectOnly
* the current turn doesn't allow any table manipulation
*/
- public HumanTurnControl(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;
@@ -58,6 +59,21 @@ public class HumanTurnControl extends AbstractTurnControl {
this.timer = new TurnTimer(view);
}
+ /**
+ * Get a factory for this turn control
+ *
+ * @return factory
+ */
+ public static TurnControlFactory getFactory() {
+ return new TurnControlFactory() {
+ @Override
+ public ITurnControl create(IHand hand, ITable table, IView view,
+ boolean inspectOnly) {
+ return new HumanTurnControl(hand, table, view, inspectOnly);
+ }
+ };
+ }
+
/** Test only constructor **/
HumanTurnControl(IHand hand, ITable table, IView view, ITurnTimer testTimer) {
this.hand = hand;
@@ -80,13 +96,14 @@ public class HumanTurnControl extends AbstractTurnControl {
connections.add(timer.getTimeRunOutEvent().add(endOfTurnListener));
connections.add(view.getPlayerPanel().getEndTurnEvent()
.add(endOfTurnListener));
-
- connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() {
- @Override
- public void handle() {
- endOfTurn(true);
- }
- }));
+
+ connections.add(view.getPlayerPanel().getRedealEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ endOfTurn(true);
+ }
+ }));
addHandPanelHandlers();
addStoneCollectionHandlers();
diff --git a/src/jrummikub/control/turn/TurnControlFactory.java b/src/jrummikub/control/turn/TurnControlFactory.java
new file mode 100644
index 0000000..3af910b
--- /dev/null
+++ b/src/jrummikub/control/turn/TurnControlFactory.java
@@ -0,0 +1,9 @@
+package jrummikub.control.turn;
+
+import jrummikub.model.IHand;
+import jrummikub.model.ITable;
+import jrummikub.view.IView;
+
+public interface TurnControlFactory {
+ public ITurnControl create(IHand hand, ITable table, IView view, boolean inspectOnly);
+}
diff --git a/src/jrummikub/model/PlayerSettings.java b/src/jrummikub/model/PlayerSettings.java
index 5ba01b5..217b1fc 100644
--- a/src/jrummikub/model/PlayerSettings.java
+++ b/src/jrummikub/model/PlayerSettings.java
@@ -2,24 +2,46 @@ package jrummikub.model;
import java.awt.Color;
+import jrummikub.control.turn.HumanTurnControl;
+import jrummikub.control.turn.TurnControlFactory;
+
/**
* The settings of a player
*/
public class PlayerSettings {
private String name;
private Color color;
+ private TurnControlFactory turnControlFactory;
/**
+ * Create a new player
+ *
+ * @param name
+ * the player's name
+ * @param color
+ * the player's color
+ * @param turnControlFactory
+ * the player's {@link TurnControlFactory}
+ */
+ public PlayerSettings(String name, Color color,
+ TurnControlFactory turnControlFactory) {
+ this.name = name;
+ this.color = color;
+ this.turnControlFactory = turnControlFactory;
+ }
+
+ /**
* Create a new human player
*
* @param name
- * the player's name
+ * the player's name
* @param color
- * the player's color
+ * the player's color
*/
public PlayerSettings(String name, Color color) {
this.name = name;
this.color = color;
+ this.turnControlFactory = HumanTurnControl.getFactory();
}
/**
@@ -44,7 +66,7 @@ public class PlayerSettings {
* Sets the player's color
*
* @param color
- * the new color
+ * the new color
*/
public void setColor(Color color) {
this.color = color;
@@ -54,9 +76,28 @@ public class PlayerSettings {
* Sets the player's name
*
* @param name
- * the new name
+ * the new name
*/
public void setName(String name) {
this.name = name;
}
+
+ /**
+ * Set the player's TurnControlFactory
+ *
+ * @param turnControlFactory
+ * player's TurnControlFactory
+ */
+ public void setTurnControlFactory(TurnControlFactory turnControlFactory) {
+ this.turnControlFactory = turnControlFactory;
+ }
+
+ /**
+ * Get the player's TurnControlFactory
+ *
+ * @return player's TurnControlFactory
+ */
+ public TurnControlFactory getTurnControlFactory() {
+ return turnControlFactory;
+ }
}