summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/RoundControl.java20
-rw-r--r--src/jrummikub/control/turn/AbstractTurnControl.java8
-rw-r--r--src/jrummikub/control/turn/BaseAIControl.java23
-rw-r--r--src/jrummikub/control/turn/HumanTurnControl.java57
-rw-r--r--src/jrummikub/control/turn/ITurnControl.java17
-rw-r--r--src/jrummikub/control/turn/TurnControlFactory.java8
-rw-r--r--src/jrummikub/control/turn/TurnMode.java13
-rw-r--r--src/jrummikub/view/IPlayerPanel.java16
-rw-r--r--src/jrummikub/view/IView.java20
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java32
10 files changed, 135 insertions, 79 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 86f8e05..4819aad 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -9,6 +9,7 @@ import java.util.Set;
import jrummikub.control.turn.ITurnControl;
import jrummikub.control.turn.TurnControlFactory;
+import jrummikub.control.turn.TurnMode;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
import jrummikub.model.IPlayer;
@@ -103,19 +104,24 @@ public class RoundControl {
return;
boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
.getTurnControlType() == HUMAN;
- boolean inspectOnly = roundState.getTurnNumber() < 1;
- boolean mayRedeal = inspectOnly
- && roundState.getActivePlayer().getHand().getIdenticalStoneCount() >= 3;
+
+ TurnMode turnMode = TurnMode.NORMAL_TURN;
+
+ if (roundState.getTurnNumber() < 1) {
+ turnMode = TurnMode.INSPECT_ONLY;
+ if (roundState.getActivePlayer().getHand().getIdenticalStoneCount() >= 3) {
+ turnMode = TurnMode.MAY_REDEAL;
+ }
+ }
if (isHuman) {
- view.getPlayerPanel().setEndTurnMode(inspectOnly, mayRedeal);
+ view.getPlayerPanel().setEndTurnMode(turnMode);
}
turnControl = TurnControlFactory.getFactory(
roundState.getActivePlayer().getPlayerSettings().getTurnControlType())
.create();
- turnControl
- .setup(roundState.getGameSettings(), roundState.getActivePlayer(),
- clonedTable, view, inspectOnly, mayRedeal);
+ turnControl.setup(roundState.getGameSettings(),
+ roundState.getActivePlayer(), clonedTable, view, turnMode);
turnControl.getEndOfTurnEvent().add(new IListener() {
@Override
public void handle() {
diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java
index 3c89708..688e147 100644
--- a/src/jrummikub/control/turn/AbstractTurnControl.java
+++ b/src/jrummikub/control/turn/AbstractTurnControl.java
@@ -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;
}
} \ No newline at end of file
diff --git a/src/jrummikub/control/turn/BaseAIControl.java b/src/jrummikub/control/turn/BaseAIControl.java
index b02c127..3c48341 100644
--- a/src/jrummikub/control/turn/BaseAIControl.java
+++ b/src/jrummikub/control/turn/BaseAIControl.java
@@ -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) {
diff --git a/src/jrummikub/control/turn/HumanTurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java
index d7f7721..55b17f2 100644
--- a/src/jrummikub/control/turn/HumanTurnControl.java
+++ b/src/jrummikub/control/turn/HumanTurnControl.java
@@ -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)
- addTablePanelHandlers();
-
- addListeners();
+ if (turnMode == TurnMode.NORMAL_TURN) {
+ addTablePanelHandlers();
+ }
+
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;
diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java
index 4616070..edf1e4d 100644
--- a/src/jrummikub/control/turn/ITurnControl.java
+++ b/src/jrummikub/control/turn/ITurnControl.java
@@ -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
diff --git a/src/jrummikub/control/turn/TurnControlFactory.java b/src/jrummikub/control/turn/TurnControlFactory.java
index 4474763..95396aa 100644
--- a/src/jrummikub/control/turn/TurnControlFactory.java
+++ b/src/jrummikub/control/turn/TurnControlFactory.java
@@ -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) {
diff --git a/src/jrummikub/control/turn/TurnMode.java b/src/jrummikub/control/turn/TurnMode.java
new file mode 100644
index 0000000..550c1f7
--- /dev/null
+++ b/src/jrummikub/control/turn/TurnMode.java
@@ -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
+}
diff --git a/src/jrummikub/view/IPlayerPanel.java b/src/jrummikub/view/IPlayerPanel.java
index 0181a9e..133adba 100644
--- a/src/jrummikub/view/IPlayerPanel.java
+++ b/src/jrummikub/view/IPlayerPanel.java
@@ -1,5 +1,6 @@
package jrummikub.view;
+import jrummikub.control.turn.TurnMode;
import jrummikub.util.IEvent;
/**
@@ -10,7 +11,7 @@ public interface IPlayerPanel {
* Sets the time the player has left for his turn
*
* @param time
- * the time left
+ * the time left
*/
public void setTimeLeft(int time);
@@ -23,8 +24,8 @@ public interface IPlayerPanel {
public IEvent getSortByGroupsEvent();
/**
- * The sort by runs event is emitted when the player wants to sort his
- * stones by runs
+ * The sort by runs event is emitted when the player wants to sort his stones
+ * by runs
*
* @return the event
*/
@@ -47,11 +48,8 @@ public interface IPlayerPanel {
/**
* Sets the buttons available to end the turn
*
- * @param inspectOnly
- * true for each player's first turn
- * @param mayRedeal
- * true if the player is allowed to trigger a redealing of all
- * stones
+ * @param turnMode
+ * the {@link TurnMode}
*/
- public abstract void setEndTurnMode(boolean inspectOnly, boolean mayRedeal);
+ public abstract void setEndTurnMode(TurnMode turnMode);
}
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index 41dbdf1..ab86b4b 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -121,9 +121,27 @@ public interface IView {
*/
public IEvent getNewGameEvent();
+ /**
+ * Sets the bottom panels type
+ *
+ * @param type
+ * the type of the bottom panel
+ */
public void setBottomPanel(BottomPanelType type);
+ /**
+ * Different types of bottom panels
+ */
public enum BottomPanelType {
- START_GAME_PANEL, START_TURN_PANEL, HUMAN_HAND_PANEL, COMPUTER_HAND_PANEL, WIN_PANEL
+ /** */
+ START_GAME_PANEL,
+ /** */
+ START_TURN_PANEL,
+ /** */
+ HUMAN_HAND_PANEL,
+ /** */
+ COMPUTER_HAND_PANEL,
+ /** */
+ WIN_PANEL
}
}
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index a16b32f..dcd22ed 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -17,6 +17,7 @@ import javax.swing.JProgressBar;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
+import jrummikub.control.turn.TurnMode;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.util.Event;
@@ -268,8 +269,6 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
addComponentListener(rescaleListener);
hand.addComponentListener(rescaleListener);
-
- setEndTurnMode(true, true);
}
private class LeftPanelResizeListener extends ComponentAdapter {
@@ -363,16 +362,27 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
}
@Override
- public void setEndTurnMode(boolean inspectOnly, boolean mayRedeal) {
- if (!inspectOnly) {
- endTurnButton.setText("Zug beenden");
- } else if (!mayRedeal) {
+ public void setEndTurnMode(TurnMode turnMode) {
+
+ switch (turnMode) {
+ case MAY_REDEAL:
+ endTurnButton.setVisible(false);
+ keepStonesButton.setVisible(true);
+ redealButton.setVisible(true);
+ break;
+ case INSPECT_ONLY:
endTurnButton.setText("N\u00e4chster Spieler");
+ endTurnButton.setVisible(true);
+ keepStonesButton.setVisible(false);
+ redealButton.setVisible(false);
+ break;
+ case NORMAL_TURN:
+ endTurnButton.setText("Zug beenden");
+ endTurnButton.setVisible(true);
+ keepStonesButton.setVisible(false);
+ redealButton.setVisible(false);
+ break;
}
- boolean smallButtons = mayRedeal && inspectOnly;
- endTurnButton.setVisible(!smallButtons);
- keepStonesButton.setVisible(smallButtons);
- redealButton.setVisible(smallButtons);
}
void showButtons(boolean show) {
@@ -397,7 +407,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
sortByGroupsButton.setEnabled(enable);
sortByRunsButton.setEnabled(enable);
if (!enable) {
- setEndTurnMode(false, false);
+ setEndTurnMode(TurnMode.NORMAL_TURN);
endTurnButton.setText("<html><center>Computer denkt nach");
hand.setStones(Collections.<Pair<Stone, Position>> emptyList());
handRowDownButton.setForeground(Color.GRAY);