Metric fixes
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@358 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
6319ec8ab6
commit
640a1e0fb6
13 changed files with 153 additions and 99 deletions
|
@ -20,8 +20,7 @@ public abstract class AbstractTurnControl implements ITurnControl {
|
|||
protected IHand hand;
|
||||
protected ITable table;
|
||||
protected IView view;
|
||||
protected boolean inspectOnly;
|
||||
protected boolean mayRedeal;
|
||||
protected TurnMode turnMode;
|
||||
|
||||
@Override
|
||||
public IEvent getEndOfTurnEvent() {
|
||||
|
@ -35,14 +34,13 @@ public abstract class AbstractTurnControl implements ITurnControl {
|
|||
|
||||
@Override
|
||||
public void setup(GameSettings settings, IPlayer player, ITable table,
|
||||
IView view, boolean inspectOnly, boolean mayRedeal) {
|
||||
IView view, TurnMode turnMode) {
|
||||
this.settings = settings;
|
||||
this.player = player;
|
||||
this.hand = player.getHand();
|
||||
this.table = table;
|
||||
this.view = view;
|
||||
this.inspectOnly = inspectOnly;
|
||||
this.mayRedeal = mayRedeal;
|
||||
this.turnMode = turnMode;
|
||||
}
|
||||
|
||||
}
|
|
@ -63,14 +63,16 @@ public class BaseAIControl extends AbstractTurnControl {
|
|||
}
|
||||
|
||||
private void compute() {
|
||||
if (inspectOnly) {
|
||||
if (mayRedeal) {
|
||||
emitRedeal();
|
||||
} else {
|
||||
emitEndOfTurn();
|
||||
}
|
||||
} else {
|
||||
switch (turnMode) {
|
||||
case MAY_REDEAL:
|
||||
emitRedeal();
|
||||
break;
|
||||
case INSPECT_ONLY:
|
||||
emitEndOfTurn();
|
||||
break;
|
||||
case NORMAL_TURN:
|
||||
turn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +126,8 @@ public class BaseAIControl extends AbstractTurnControl {
|
|||
for (Stone stone : set) {
|
||||
handStones.add(pickUpMatchingStone(stone));
|
||||
}
|
||||
table.drop(new StoneSet(handStones), new Position((float)Math.random() * 30 - 15, (float)Math.random() * 6 - 3));
|
||||
table.drop(new StoneSet(handStones), new Position(
|
||||
(float) Math.random() * 30 - 15, (float) Math.random() * 6 - 3));
|
||||
}
|
||||
|
||||
emitEndOfTurn();
|
||||
|
@ -144,8 +147,8 @@ public class BaseAIControl extends AbstractTurnControl {
|
|||
|
||||
private void emitEndOfTurn() {
|
||||
long timeElapsed = System.currentTimeMillis() - startTime;
|
||||
long timeNeeded = Math.min(
|
||||
(long) (1000 + Math.random() * hand.getSize() * 100), 50000);
|
||||
long timeNeeded = Math.min((long) (1000 + Math.random() * hand.getSize()
|
||||
* 100), 50000);
|
||||
long waitTime = timeNeeded - timeElapsed;
|
||||
|
||||
if (waitTime > 0) {
|
||||
|
|
|
@ -60,32 +60,23 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
if (this.timer == null) {
|
||||
this.timer = new TurnTimer(view);
|
||||
}
|
||||
IListener endOfTurnListener = new IListener() {
|
||||
|
||||
connections.add(timer.getTimeRunOutEvent().add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn(false);
|
||||
}
|
||||
};
|
||||
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);
|
||||
}
|
||||
}));
|
||||
}));
|
||||
addButtonHandlers();
|
||||
|
||||
addHandPanelHandlers();
|
||||
addStoneCollectionHandlers();
|
||||
if (!inspectOnly)
|
||||
|
||||
if (turnMode == TurnMode.NORMAL_TURN) {
|
||||
addTablePanelHandlers();
|
||||
|
||||
addListeners();
|
||||
|
||||
}
|
||||
|
||||
view.getHandPanel().setStones(hand.clone());
|
||||
view.getHandPanel().resetCurrentRow();
|
||||
view.setBottomPanel(BottomPanelType.HUMAN_HAND_PANEL);
|
||||
|
@ -93,7 +84,7 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
timer.startTimer();
|
||||
}
|
||||
|
||||
private void addListeners() {
|
||||
private void addButtonHandlers() {
|
||||
connections.add(view.getPlayerPanel().getSortByGroupsEvent()
|
||||
.add(new IListener() {
|
||||
@Override
|
||||
|
@ -109,6 +100,22 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
sortByRuns();
|
||||
}
|
||||
}));
|
||||
|
||||
connections.add(view.getPlayerPanel().getEndTurnEvent()
|
||||
.add(new IListener() {
|
||||
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn(false);
|
||||
}
|
||||
}));
|
||||
|
||||
connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() {
|
||||
@Override
|
||||
public void handle() {
|
||||
endOfTurn(true);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void addHandPanelHandlers() {
|
||||
|
@ -425,12 +432,15 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
table.drop(joinedSet, newPos);
|
||||
} else {
|
||||
StoneSet joinedSet = new StoneSet(selectedStones).join(newSet);
|
||||
table.drop(joinedSet, new Position(newPos.getX()
|
||||
- selectedStones.size(), newPos.getY()));
|
||||
table.drop(joinedSet,
|
||||
new Position(newPos.getX() - selectedStones.size(), newPos.getY()));
|
||||
}
|
||||
} else {
|
||||
table.drop(new StoneSet(selectedStones), new Position(pos.getX()
|
||||
+ (set.size() - selectedStones.size()) * 0.5f, pos.getY()));
|
||||
table.drop(
|
||||
new StoneSet(selectedStones),
|
||||
new Position(
|
||||
pos.getX() + (set.size() - selectedStones.size()) * 0.5f, pos
|
||||
.getY()));
|
||||
}
|
||||
|
||||
selectedStones.clear();
|
||||
|
@ -525,8 +535,7 @@ public class HumanTurnControl extends AbstractTurnControl {
|
|||
static class HandStonePositionComparator implements
|
||||
Comparator<Pair<Stone, Position>> {
|
||||
@Override
|
||||
public int compare(Pair<Stone, Position> pair1,
|
||||
Pair<Stone, Position> pair2) {
|
||||
public int compare(Pair<Stone, Position> pair1, Pair<Stone, Position> pair2) {
|
||||
Position pos1 = pair1.getSecond(), pos2 = pair2.getSecond();
|
||||
if (pos1.getY() < pos2.getY()) {
|
||||
return -1;
|
||||
|
|
|
@ -11,26 +11,23 @@ import jrummikub.view.IView;
|
|||
* Interface containing shared methods of human and computer turn control
|
||||
*
|
||||
*/
|
||||
// TODO zu viele parameter
|
||||
public interface ITurnControl {
|
||||
/**
|
||||
* Start the turn
|
||||
*
|
||||
* @param settings
|
||||
* the game settings
|
||||
* the game settings
|
||||
* @param player
|
||||
* the active player
|
||||
* the active player
|
||||
* @param table
|
||||
* current 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
|
||||
* view for user interaction.
|
||||
* @param turnMode
|
||||
* whether it is turn zero and if one may redeal
|
||||
*/
|
||||
public void setup(GameSettings settings, IPlayer player, ITable table,
|
||||
IView view, boolean inspectOnly, boolean mayRedeal);
|
||||
IView view, TurnMode turnMode);
|
||||
|
||||
/**
|
||||
* Get the event that is emitted when the turn is over
|
||||
|
|
|
@ -16,14 +16,18 @@ public abstract class TurnControlFactory {
|
|||
COMPUTER
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new turn control instance
|
||||
*
|
||||
* @return the turn control
|
||||
*/
|
||||
public abstract ITurnControl create();
|
||||
|
||||
/**
|
||||
* returns the turn control factory for the specified type
|
||||
*
|
||||
* @param type
|
||||
* Human or Computer
|
||||
* Human or Computer
|
||||
* @return TurnControlFactory for the player kind
|
||||
*/
|
||||
static public TurnControlFactory getFactory(Type type) {
|
||||
|
|
13
src/jrummikub/control/turn/TurnMode.java
Normal file
13
src/jrummikub/control/turn/TurnMode.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package jrummikub.control.turn;
|
||||
|
||||
/**
|
||||
* Different kinds of turns
|
||||
*/
|
||||
public enum TurnMode {
|
||||
/** Turn zero with possibility to redeal */
|
||||
MAY_REDEAL,
|
||||
/** Turn zero without possibility to redeal */
|
||||
INSPECT_ONLY,
|
||||
/** A normal turn */
|
||||
NORMAL_TURN
|
||||
}
|
Reference in a new issue