Added TurnControlFactory

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@308 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-29 19:46:53 +02:00
parent 73f6fb9c1b
commit eb7ccb46c5
4 changed files with 86 additions and 15 deletions

View file

@ -95,8 +95,12 @@ public class RoundControl {
view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal); view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
ITurnControl turnControl = new HumanTurnControl(roundState.getActivePlayer() ITurnControl turnControl = roundState
.getHand(), clonedTable, view, inspectOnly); .getActivePlayer()
.getPlayerSettings()
.getTurnControlFactory()
.create(roundState.getActivePlayer().getHand(), clonedTable,
view, inspectOnly);
turnControl.getEndOfTurnEvent().add(new IListener() { turnControl.getEndOfTurnEvent().add(new IListener() {
@Override @Override

View file

@ -50,7 +50,8 @@ public class HumanTurnControl extends AbstractTurnControl {
* @param inspectOnly * @param inspectOnly
* the current turn doesn't allow any table manipulation * 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.hand = hand;
this.table = table; this.table = table;
this.view = view; this.view = view;
@ -58,6 +59,21 @@ public class HumanTurnControl extends AbstractTurnControl {
this.timer = new TurnTimer(view); 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 **/ /** Test only constructor **/
HumanTurnControl(IHand hand, ITable table, IView view, ITurnTimer testTimer) { HumanTurnControl(IHand hand, ITable table, IView view, ITurnTimer testTimer) {
this.hand = hand; this.hand = hand;
@ -81,7 +97,8 @@ public class HumanTurnControl extends AbstractTurnControl {
connections.add(view.getPlayerPanel().getEndTurnEvent() connections.add(view.getPlayerPanel().getEndTurnEvent()
.add(endOfTurnListener)); .add(endOfTurnListener));
connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() { connections.add(view.getPlayerPanel().getRedealEvent()
.add(new IListener() {
@Override @Override
public void handle() { public void handle() {
endOfTurn(true); endOfTurn(true);

View file

@ -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);
}

View file

@ -2,12 +2,33 @@ package jrummikub.model;
import java.awt.Color; import java.awt.Color;
import jrummikub.control.turn.HumanTurnControl;
import jrummikub.control.turn.TurnControlFactory;
/** /**
* The settings of a player * The settings of a player
*/ */
public class PlayerSettings { public class PlayerSettings {
private String name; private String name;
private Color color; 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 * Create a new human player
@ -20,6 +41,7 @@ public class PlayerSettings {
public PlayerSettings(String name, Color color) { public PlayerSettings(String name, Color color) {
this.name = name; this.name = name;
this.color = color; this.color = color;
this.turnControlFactory = HumanTurnControl.getFactory();
} }
/** /**
@ -59,4 +81,23 @@ public class PlayerSettings {
public void setName(String name) { public void setName(String name) {
this.name = 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;
}
} }