Created interface and abstract base class for turn control

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@307 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-05-29 19:46:50 +02:00
parent f62b953c9e
commit 73f6fb9c1b
5 changed files with 76 additions and 40 deletions

View file

@ -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() {

View file

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

View file

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

View file

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