summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/control/RoundControl.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/control/RoundControl.java')
-rw-r--r--src/jrummikub/control/RoundControl.java40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index f536acc..63accaa 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -1,6 +1,8 @@
package jrummikub.control;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import jrummikub.model.IGameState;
@@ -9,35 +11,39 @@ import jrummikub.model.ITable;
import jrummikub.model.Position;
import jrummikub.model.Stone;
import jrummikub.model.StoneSet;
+import jrummikub.util.Connection;
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
import jrummikub.util.IListener;
import jrummikub.util.Pair;
import jrummikub.view.IView;
public class RoundControl {
- // TODO move to game control once existent
- final static int HAND_HEIGHT = 2;
- final static int HAND_WIDTH = 14;
private IGameState gameState;
private IView view;
private ITable clonedTable;
+ private Event endRoundEvent = new Event();
+ private List<Connection> connections = new ArrayList<Connection>();
public RoundControl(IGameState gameState, IView view) {
this.gameState = gameState;
this.view = view;
- view.getPlayerPanel().getHandPanel().setHandHeight(HAND_HEIGHT);
- view.getPlayerPanel().getHandPanel().setHandWidth(HAND_WIDTH);
+ }
+
+ public IEvent getEndRoundEvent() {
+ return endRoundEvent;
}
public void startRound() {
deal();
- view.getStartTurnEvent().add(new IListener() {
+ connections.add(view.getStartTurnEvent().add(new IListener() {
@Override
public void handle() {
startTurn();
}
- });
+ }));
prepareTurn();
}
@@ -58,13 +64,13 @@ public class RoundControl {
private void startTurn() {
TurnControl turnControl = new TurnControl(gameState.getActivePlayer()
.getHand(), clonedTable, view);
- turnControl.getEndOfTurnEvent().add(new IListener() {
+ connections.add(turnControl.getEndOfTurnEvent().add(new IListener() {
@Override
public void handle() {
endOfTurn();
}
- });
+ }));
turnControl.startTurn();
}
@@ -73,14 +79,17 @@ public class RoundControl {
for (int i = 0; i < gameState.getPlayerCount(); i++) {
IHand hand = gameState.getNthNextPlayer(i).getHand();
for (int j = 0; j < 7; j++) {
- hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 0));
- hand.drop(gameState.getGameHeap().drawStone(), new Position(j, 1));
+ hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
+ 0));
+ hand.drop(gameState.getGameHeap().drawStone(), new Position(j,
+ 1));
}
}
}
private void endOfTurn() {
- Set<Stone> tableDiff = tableDifference(gameState.getTable(), clonedTable);
+ Set<Stone> tableDiff = tableDifference(gameState.getTable(),
+ clonedTable);
if (!tableDiff.isEmpty()) { // Player has made a move
if (clonedTable.isValid()) {
@@ -128,7 +137,8 @@ public class RoundControl {
.getActivePlayer()
.getHand()
.drop(gameState.getGameHeap().drawStone(),
- new Position(HAND_WIDTH - 1, HAND_HEIGHT - 1));
+ new Position(GameControl.HAND_WIDTH - 1,
+ GameControl.HAND_HEIGHT - 1));
}
private void dealPenalty(int count) {
@@ -137,6 +147,10 @@ public class RoundControl {
}
private void win() {
+ for (Connection c : connections) {
+ c.remove();
+ }
+ endRoundEvent.emit();
view.enableWinPanel(true);
}
}