summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/RoundControl.java10
-rw-r--r--src/jrummikub/control/TurnControl.java35
-rw-r--r--src/jrummikub/model/IRoundState.java14
-rw-r--r--src/jrummikub/model/RoundState.java13
4 files changed, 55 insertions, 17 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index 91bf59b..ba61dfd 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -5,6 +5,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import jrummikub.model.GameState;
import jrummikub.model.Hand;
import jrummikub.model.IHand;
import jrummikub.model.IPlayer;
@@ -87,7 +88,7 @@ public class RoundControl {
private void startTurn() {
TurnControl turnControl = new TurnControl(roundState.getActivePlayer()
- .getHand(), clonedTable, view);
+ .getHand(), clonedTable, view, roundState.getTurnNumber() < 1);
connections.add(turnControl.getEndOfTurnEvent().add(new IListener() {
@Override
@@ -126,19 +127,24 @@ public class RoundControl {
}
private void endOfTurn() {
- checkTurn();
+ if (roundState.getTurnNumber() >= 1) {
+ checkTurn();
+ }
if (roundState.getLastPlayer() == null) {
if (roundState.getGameHeap().getSize() == 0) {
roundState.setLastPlayer(roundState.getNthNextPlayer(-1));
+ roundState.nextTurn();
} else {
roundState.nextPlayer();
+ roundState.nextTurn();
}
} else {
if (roundState.getActivePlayer() == roundState.getLastPlayer()) {
endOfRound();
} else {
roundState.nextPlayer();
+ roundState.nextTurn();
}
}
if (!roundFinished) {
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java
index 4140b57..9ce08b0 100644
--- a/src/jrummikub/control/TurnControl.java
+++ b/src/jrummikub/control/TurnControl.java
@@ -35,22 +35,27 @@ public class TurnControl {
private Event endOfTurnEvent = new Event();
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.
+ * 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
+ * active player's hand
* @param table
- * current table
+ * current table
* @param view
- * view for user interaction.
+ * view for user interaction.
+ * @param inspectOnly
+ * the current turn doesn't allow any table manipulation
*/
- public TurnControl(IHand hand, ITable table, IView view) {
+ public TurnControl(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);
}
@@ -60,6 +65,7 @@ public class TurnControl {
this.table = table;
this.view = view;
this.timer = testTimer;
+ this.inspectOnly = false;
}
/**
@@ -80,7 +86,8 @@ public class TurnControl {
addHandPanelHandlers();
addStoneCollectionHandlers();
- addTablePanelHandlers();
+ if (!inspectOnly)
+ addTablePanelHandlers();
connections.add(view.getPlayerPanel().getSortByGroupsEvent()
.add(new IListener() {
@@ -419,15 +426,12 @@ public class TurnControl {
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();
@@ -527,7 +531,8 @@ public class TurnControl {
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/model/IRoundState.java b/src/jrummikub/model/IRoundState.java
index faed6cf..1f6da15 100644
--- a/src/jrummikub/model/IRoundState.java
+++ b/src/jrummikub/model/IRoundState.java
@@ -94,4 +94,18 @@ public interface IRoundState {
*/
public void setActivePlayerNumber(int i);
+ /**
+ * Gets the number of the current turn. Numbers smaller than one indicate
+ * hand inspection turns
+ *
+ * @return current turn number
+ */
+ public abstract int getTurnNumber();
+
+ /**
+ * Increments the turn number
+ *
+ */
+ public void nextTurn();
+
} \ No newline at end of file
diff --git a/src/jrummikub/model/RoundState.java b/src/jrummikub/model/RoundState.java
index eb87247..65bc120 100644
--- a/src/jrummikub/model/RoundState.java
+++ b/src/jrummikub/model/RoundState.java
@@ -12,6 +12,7 @@ public class RoundState implements IRoundState {
private int activePlayer;
private StoneHeap gameHeap;
private IPlayer lastPlayer;
+ private int turnNumber;
/**
* Create a new RoundState with an empty table
@@ -29,6 +30,8 @@ public class RoundState implements IRoundState {
players.add(new Player(playerSettings, gameSettings));
}
+ turnNumber = 1-gameSettings.getPlayerList().size();
+
activePlayer = 0;
gameHeap = new StoneHeap();
}
@@ -104,4 +107,14 @@ public class RoundState implements IRoundState {
public IPlayer getLastPlayer() {
return lastPlayer;
}
+
+ @Override
+ public int getTurnNumber() {
+ return turnNumber;
+ }
+
+ @Override
+ public void nextTurn() {
+ turnNumber++;
+ }
}