Created dummy base AI control
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@311 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
f6a3409ed5
commit
65d08ea450
7 changed files with 123 additions and 82 deletions
|
@ -95,14 +95,11 @@ public class RoundControl {
|
|||
|
||||
view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
|
||||
|
||||
ITurnControl turnControl = roundState
|
||||
.getActivePlayer()
|
||||
.getPlayerSettings()
|
||||
.getTurnControlFactory()
|
||||
.create(roundState.getActivePlayer().getHand(), clonedTable,
|
||||
view, inspectOnly);
|
||||
ITurnControl turnControl = roundState.getActivePlayer()
|
||||
.getPlayerSettings().getTurnControlFactory().create();
|
||||
turnControl.setup(roundState.getActivePlayer().getHand(), clonedTable,
|
||||
view, inspectOnly, mayRedeal);
|
||||
turnControl.getEndOfTurnEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn();
|
||||
|
@ -115,7 +112,6 @@ public class RoundControl {
|
|||
redeal();
|
||||
}
|
||||
});
|
||||
|
||||
turnControl.startTurn();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package jrummikub.control.turn;
|
||||
|
||||
import jrummikub.model.IHand;
|
||||
import jrummikub.model.ITable;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
/**
|
||||
* Abstract base class for TurnControls
|
||||
|
@ -10,9 +13,12 @@ public abstract class AbstractTurnControl implements ITurnControl {
|
|||
|
||||
protected Event endOfTurnEvent = new Event();
|
||||
protected Event redealEvent = new Event();
|
||||
|
||||
@Override
|
||||
public abstract void startTurn();
|
||||
protected IHand hand;
|
||||
protected ITable table;
|
||||
protected IView view;
|
||||
protected boolean inspectOnly;
|
||||
protected boolean mayRedeal;
|
||||
|
||||
|
||||
@Override
|
||||
public IEvent getEndOfTurnEvent() {
|
||||
|
@ -23,5 +29,15 @@ public abstract class AbstractTurnControl implements ITurnControl {
|
|||
public Event getRedealEvent() {
|
||||
return redealEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setup(IHand hand, ITable table, IView view,
|
||||
boolean inspectOnly, boolean mayRedeal) {
|
||||
this.hand = hand;
|
||||
this.table = table;
|
||||
this.view = view;
|
||||
this.inspectOnly = inspectOnly;
|
||||
this.mayRedeal = mayRedeal;
|
||||
}
|
||||
|
||||
}
|
28
src/jrummikub/control/turn/BaseAIControl.java
Normal file
28
src/jrummikub/control/turn/BaseAIControl.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package jrummikub.control.turn;
|
||||
|
||||
import jrummikub.model.IHand;
|
||||
import jrummikub.model.ITable;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
|
||||
public class BaseAIControl extends AbstractTurnControl {
|
||||
|
||||
@Override
|
||||
public void startTurn() {
|
||||
if (mayRedeal) {
|
||||
redealEvent.emit();
|
||||
} else {
|
||||
endOfTurnEvent.emit();
|
||||
}
|
||||
}
|
||||
|
||||
static public TurnControlFactory getFactory() {
|
||||
return new TurnControlFactory() {
|
||||
@Override
|
||||
public ITurnControl create() {
|
||||
return new BaseAIControl();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -26,37 +26,16 @@ import jrummikub.view.IView;
|
|||
* Controller for a single turn made by a human player
|
||||
*/
|
||||
public class HumanTurnControl extends AbstractTurnControl {
|
||||
private IHand hand;
|
||||
private ITable table;
|
||||
private ITurnTimer timer;
|
||||
private IView view;
|
||||
|
||||
private List<Stone> selectedStones = new ArrayList<Stone>();
|
||||
|
||||
private List<Connection> connections = new ArrayList<Connection>();
|
||||
|
||||
private boolean inspectOnly;
|
||||
|
||||
/**
|
||||
* Create a new TurnControl using a given hand (of the active player), a
|
||||
* given table and a given view for user interaction.
|
||||
*
|
||||
* @param hand
|
||||
* active player's hand
|
||||
* @param table
|
||||
* current table
|
||||
* @param view
|
||||
* view for user interaction.
|
||||
* @param inspectOnly
|
||||
* the current turn doesn't allow any table manipulation
|
||||
* Create a new human player's turn control
|
||||
*/
|
||||
public HumanTurnControl(IHand hand, ITable table, IView view,
|
||||
boolean inspectOnly) {
|
||||
this.hand = hand;
|
||||
this.table = table;
|
||||
this.view = view;
|
||||
this.inspectOnly = inspectOnly;
|
||||
this.timer = new TurnTimer(view);
|
||||
public HumanTurnControl() {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -67,25 +46,22 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
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);
|
||||
public ITurnControl create() {
|
||||
return new HumanTurnControl();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/** Test only constructor **/
|
||||
HumanTurnControl(IHand hand, ITable table, IView view, ITurnTimer testTimer) {
|
||||
this.hand = hand;
|
||||
this.table = table;
|
||||
this.view = view;
|
||||
HumanTurnControl(ITurnTimer testTimer) {
|
||||
this.timer = testTimer;
|
||||
this.inspectOnly = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startTurn() {
|
||||
|
||||
if (this.timer == null) {
|
||||
this.timer = new TurnTimer(view);
|
||||
}
|
||||
IListener endOfTurnListener = new IListener() {
|
||||
|
||||
@Override
|
||||
|
@ -565,5 +541,4 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,14 +1,28 @@
|
|||
package jrummikub.control.turn;
|
||||
|
||||
import jrummikub.model.IHand;
|
||||
import jrummikub.model.ITable;
|
||||
import jrummikub.util.Event;
|
||||
import jrummikub.util.IEvent;
|
||||
import jrummikub.view.IView;
|
||||
|
||||
public interface ITurnControl {
|
||||
|
||||
/**
|
||||
* Start the turn
|
||||
*
|
||||
* @param hand
|
||||
* active player's hand
|
||||
* @param table
|
||||
* current table
|
||||
* @param view
|
||||
* view for user interaction.
|
||||
* @param inspectOnly
|
||||
* the current turn doesn't allow any table manipulation
|
||||
* @param mayRedeal
|
||||
* true when the current player may decide to redeal
|
||||
*/
|
||||
public abstract void startTurn();
|
||||
public abstract void setup(IHand hand, ITable table, IView view,
|
||||
boolean inspectOnly, boolean mayRedeal);
|
||||
|
||||
/**
|
||||
* Get the event that is emitted when the turn is over
|
||||
|
@ -24,4 +38,9 @@ public interface ITurnControl {
|
|||
*/
|
||||
public abstract Event getRedealEvent();
|
||||
|
||||
/**
|
||||
* Start the turn
|
||||
*/
|
||||
public abstract void startTurn();
|
||||
|
||||
}
|
|
@ -5,5 +5,5 @@ import jrummikub.model.ITable;
|
|||
import jrummikub.view.IView;
|
||||
|
||||
public interface TurnControlFactory {
|
||||
public ITurnControl create(IHand hand, ITable table, IView view, boolean inspectOnly);
|
||||
public ITurnControl create();
|
||||
}
|
||||
|
|
Reference in a new issue