summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/turn
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/turn')
-rw-r--r--src/jrummikub/control/turn/AbstractTurnControl.java32
-rw-r--r--src/jrummikub/control/turn/BaseAIControl.java26
-rw-r--r--src/jrummikub/control/turn/HumanTurnControl.java33
-rw-r--r--src/jrummikub/control/turn/ITurnControl.java10
-rw-r--r--src/jrummikub/control/turn/TurnControlFactory.java8
5 files changed, 65 insertions, 44 deletions
diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java
index ae1e155..84c478a 100644
--- a/src/jrummikub/control/turn/AbstractTurnControl.java
+++ b/src/jrummikub/control/turn/AbstractTurnControl.java
@@ -16,7 +16,6 @@ import jrummikub.view.IView;
* Abstract base class for TurnControls
*/
public abstract class AbstractTurnControl implements ITurnControl {
-
protected Event endOfTurnEvent = new Event();
protected Event redealEvent = new Event();
protected TurnInfo turnInfo;
@@ -24,8 +23,7 @@ public abstract class AbstractTurnControl implements ITurnControl {
protected IView view;
protected ITurnTimer timer;
protected List<Connection> connections = new ArrayList<Connection>();
-
-
+
@Override
public IEvent getEndOfTurnEvent() {
return endOfTurnEvent;
@@ -35,7 +33,17 @@ public abstract class AbstractTurnControl implements ITurnControl {
public IEvent getRedealEvent() {
return redealEvent;
}
-
+
+ private void pauseTurn() {
+ timer.stopTimer();
+ view.enablePauseMode(true);
+ }
+
+ private void resumeTurn() {
+ timer.startTimer();
+ view.enablePauseMode(false);
+ }
+
protected abstract void timeOut();
@Override
@@ -52,15 +60,27 @@ public abstract class AbstractTurnControl implements ITurnControl {
timeOut();
}
}));
+ connections.add(view.getPauseEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ pauseTurn();
+ }
+ }));
+ connections.add(view.getEndPauseEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ resumeTurn();
+ }
+ }));
}
-
+
protected void cleanUp() {
timer.stopTimer();
for (Connection c : connections) {
c.remove();
}
}
-
+
public void abortTurn() {
cleanUp();
}
diff --git a/src/jrummikub/control/turn/BaseAIControl.java b/src/jrummikub/control/turn/BaseAIControl.java
index 43ade18..11519c3 100644
--- a/src/jrummikub/control/turn/BaseAIControl.java
+++ b/src/jrummikub/control/turn/BaseAIControl.java
@@ -36,7 +36,7 @@ public class BaseAIControl extends AbstractTurnControl {
timer.startTimer();
computeThread.start();
}
-
+
protected void timeOut() {
cleanUp();
endOfTurnEvent.emit();
@@ -49,15 +49,15 @@ public class BaseAIControl extends AbstractTurnControl {
private void compute() {
switch (turnInfo.getTurnMode()) {
- case MAY_REDEAL:
- emitRedeal();
- break;
- case INSPECT_ONLY:
- emitEndOfTurn();
- break;
- case NORMAL_TURN:
- turn();
- break;
+ case MAY_REDEAL:
+ emitRedeal();
+ break;
+ case INSPECT_ONLY:
+ emitEndOfTurn();
+ break;
+ case NORMAL_TURN:
+ turn();
+ break;
}
}
@@ -111,8 +111,10 @@ public class BaseAIControl extends AbstractTurnControl {
for (Stone stone : set) {
handStones.add(pickUpMatchingStone(stone));
}
- turnInfo.getTable().drop(new StoneSet(handStones), new Position(
- (float) Math.random() * 30 - 15, (float) Math.random() * 6 - 3));
+ turnInfo.getTable().drop(
+ new StoneSet(handStones),
+ new Position((float) Math.random() * 30 - 15,
+ (float) Math.random() * 6 - 3));
}
emitEndOfTurn();
diff --git a/src/jrummikub/control/turn/HumanTurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java
index 02541d2..2ab7b21 100644
--- a/src/jrummikub/control/turn/HumanTurnControl.java
+++ b/src/jrummikub/control/turn/HumanTurnControl.java
@@ -48,7 +48,7 @@ public class HumanTurnControl extends AbstractTurnControl {
HumanTurnControl(ITurnTimer testTimer) {
this.timer = testTimer;
}
-
+
protected void timeOut() {
endOfTurn(false);
}
@@ -97,13 +97,12 @@ public class HumanTurnControl extends AbstractTurnControl {
}
}));
- 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);
+ }
+ }));
}
private void addHandPanelHandlers() {
@@ -304,8 +303,10 @@ public class HumanTurnControl extends AbstractTurnControl {
}
pickUpSelectedStones();
- turnInfo.getTable().drop(new StoneSet(selectedStones), new Position(position.getX()
- - selectedStones.size() * 0.5f, position.getY() - 0.5f));
+ turnInfo.getTable().drop(
+ new StoneSet(selectedStones),
+ new Position(position.getX() - selectedStones.size() * 0.5f, position
+ .getY() - 0.5f));
selectedStones.clear();
view.getTablePanel().setStoneSets(turnInfo.getTable());
@@ -421,15 +422,14 @@ public class HumanTurnControl extends AbstractTurnControl {
turnInfo.getTable().drop(joinedSet, newPos);
} else {
StoneSet joinedSet = new StoneSet(selectedStones).join(newSet);
- turnInfo.getTable().drop(joinedSet, new Position(newPos.getX()
- - selectedStones.size(), newPos.getY()));
+ turnInfo.getTable().drop(joinedSet,
+ new Position(newPos.getX() - selectedStones.size(), newPos.getY()));
}
} else {
turnInfo.getTable().drop(
new StoneSet(selectedStones),
- new Position(pos.getX()
- + (set.getSize() - selectedStones.size()) * 0.5f,
- pos.getY()));
+ new Position(pos.getX() + (set.getSize() - selectedStones.size())
+ * 0.5f, pos.getY()));
}
selectedStones.clear();
@@ -521,8 +521,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;
diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java
index 5a3d550..63290d5 100644
--- a/src/jrummikub/control/turn/ITurnControl.java
+++ b/src/jrummikub/control/turn/ITurnControl.java
@@ -44,6 +44,11 @@ public interface ITurnControl {
public void startTurn();
/**
+ * Abort the turn
+ */
+ public void abortTurn();
+
+ /**
* The TurnInfo class encapsulates all information concerning the current turn
*/
public class TurnInfo {
@@ -108,9 +113,4 @@ public interface ITurnControl {
return turnMode;
}
}
-
- /**
- * Abort the turn
- */
- public void abortTurn();
} \ No newline at end of file
diff --git a/src/jrummikub/control/turn/TurnControlFactory.java b/src/jrummikub/control/turn/TurnControlFactory.java
index 95396aa..b42f7ff 100644
--- a/src/jrummikub/control/turn/TurnControlFactory.java
+++ b/src/jrummikub/control/turn/TurnControlFactory.java
@@ -32,10 +32,10 @@ public abstract class TurnControlFactory {
*/
static public TurnControlFactory getFactory(Type type) {
switch (type) {
- case HUMAN:
- return HumanTurnControl.getFactory();
- case COMPUTER:
- return BaseAIControl.getFactory();
+ case HUMAN:
+ return HumanTurnControl.getFactory();
+ case COMPUTER:
+ return BaseAIControl.getFactory();
}
return null;
}