summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/control/GameControl.java15
-rw-r--r--src/jrummikub/control/RoundControl.java22
-rw-r--r--src/jrummikub/control/SettingsControl.java16
-rw-r--r--src/jrummikub/control/TurnControl.java27
-rw-r--r--src/jrummikub/view/impl/SettingsPanel.java16
5 files changed, 69 insertions, 27 deletions
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java
index 781af31..0ae05a6 100644
--- a/src/jrummikub/control/GameControl.java
+++ b/src/jrummikub/control/GameControl.java
@@ -19,7 +19,7 @@ import jrummikub.view.IView;
public class GameControl {
private GameSettings gameSettings;
private IView view;
- private RoundControl roundControl;
+ RoundControl roundControl;
private GameState gameState;
private List<Connection> connections = new ArrayList<Connection>();
@@ -77,10 +77,23 @@ public class GameControl {
endOfRound();
}
});
+
+ roundControl.getRestartRoundEvent().add(new IListener() {
+
+ @Override
+ public void handle() {
+ restartRound();
+ }
+ });
roundControl.startRound();
}
+ private void restartRound() {
+ roundControl = null;
+ startRound();
+ }
+
private void endOfRound() {
roundControl = null;
view.enableWinPanel(true);
diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java
index e9e9453..8aed1ce 100644
--- a/src/jrummikub/control/RoundControl.java
+++ b/src/jrummikub/control/RoundControl.java
@@ -27,7 +27,7 @@ import jrummikub.view.IView;
* Controller that manages a single round of rummikub
*/
public class RoundControl {
- private IRoundState roundState;
+ IRoundState roundState;
private IView view;
private ITable clonedTable;
private Event restartRoundEvent = new Event();
@@ -70,12 +70,7 @@ public class RoundControl {
}
}));
- connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() {
- @Override
- public void handle() {
- redeal();
- }
- }));
+
prepareTurn();
}
@@ -91,13 +86,20 @@ public class RoundControl {
private void startTurn() {
TurnControl turnControl = new TurnControl(roundState.getActivePlayer()
.getHand(), clonedTable, view, roundState.getTurnNumber() < 1);
- connections.add(turnControl.getEndOfTurnEvent().add(new IListener() {
+ turnControl.getEndOfTurnEvent().add(new IListener() {
@Override
public void handle() {
endOfTurn();
}
- }));
+ });
+
+ turnControl.getRedealEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ redeal();
+ }
+ });
turnControl.startTurn();
}
@@ -322,7 +324,7 @@ public class RoundControl {
}
private void redeal() {
- for (Connection c : connections) {
+ for (Connection c : new ArrayList<Connection>(connections)) {
c.remove();
}
restartRoundEvent.emit();
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
index 7b96e77..adcc369 100644
--- a/src/jrummikub/control/SettingsControl.java
+++ b/src/jrummikub/control/SettingsControl.java
@@ -1,8 +1,12 @@
package jrummikub.control;
+import java.awt.Color;
+
import jrummikub.model.GameSettings;
+import jrummikub.model.PlayerSettings;
import jrummikub.util.Event1;
import jrummikub.util.IEvent1;
+import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.view.IView;
@@ -31,7 +35,17 @@ public class SettingsControl {
* @Override public void handle(GameSettings settings) {
* startGame(settings); } });
*/
-
+ // TODO vvv this is just a temp. fix
+ view.getSettingsPanel().getStartGameEvent().add(new IListener() {
+
+ @Override
+ public void handle() {
+ GameSettings defaultSettings = new GameSettings();
+ defaultSettings.getPlayerList().add(new PlayerSettings("Foo", new Color(1.0f, 0, 0)));
+ defaultSettings.getPlayerList().add(new PlayerSettings("Bar", new Color(0, 1.0f, 0)));
+ startGame(defaultSettings);
+ }
+ });
view.showSettingsPanel(true);
}
diff --git a/src/jrummikub/control/TurnControl.java b/src/jrummikub/control/TurnControl.java
index 9ce08b0..1488c75 100644
--- a/src/jrummikub/control/TurnControl.java
+++ b/src/jrummikub/control/TurnControl.java
@@ -34,6 +34,7 @@ public class TurnControl {
private List<Stone> selectedStones = new ArrayList<Stone>();
private Event endOfTurnEvent = new Event();
+ private Event redealEvent = new Event();
private List<Connection> connections = new ArrayList<Connection>();
private boolean inspectOnly;
@@ -77,12 +78,19 @@ public class TurnControl {
@Override
public void handle() {
- endOfTurn();
+ 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);
+ }
+ }));
addHandPanelHandlers();
addStoneCollectionHandlers();
@@ -441,9 +449,13 @@ public class TurnControl {
view.setSelectedStones(selectedStones);
}
- private void endOfTurn() {
+ private void endOfTurn(boolean redeal) {
timer.stopTimer();
- endOfTurnEvent.emit();
+ if (redeal) {
+ redealEvent.emit();
+ } else {
+ endOfTurnEvent.emit();
+ }
for (Connection c : connections) {
c.remove();
}
@@ -549,5 +561,14 @@ public class TurnControl {
}
}
}
+
+ /**
+ * Emitted when the round is aborted and needs to be restarted
+ *
+ * @return the event
+ */
+ public Event getRedealEvent() {
+ return redealEvent;
+ }
}
diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java
index 03cfd4c..7200a16 100644
--- a/src/jrummikub/view/impl/SettingsPanel.java
+++ b/src/jrummikub/view/impl/SettingsPanel.java
@@ -31,6 +31,7 @@ import javax.swing.event.DocumentListener;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
+import jrummikub.util.Event;
import jrummikub.util.Event1;
import jrummikub.util.IEvent;
import jrummikub.util.IEvent1;
@@ -66,15 +67,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
private LinkedList<PlayerSettingsPanel> playerSettingsPanels = new LinkedList<PlayerSettingsPanel>();
private Event1<GameSettings> settingsChangeEvent = new Event1<GameSettings>();
- private Event1<GameSettings> startGameEvent = new Event1<GameSettings>();
-
- /*
- * @Override public IEvent1<GameSettings> getSettingsChangeEvent() { return
- * settingsChangeEvent; }
- *
- * @Override public IEvent1<GameSettings> getStartGameEvent() { return
- * startGameEvent; }
- */
+ private Event startGameEvent = new Event();
private void addPlayerSettings() {
// Find unused player name
@@ -177,7 +170,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- startGameEvent.emit(gameSettings);
+ startGameEvent.emit();
}
});
add(startButton, c);
@@ -392,8 +385,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
@Override
public IEvent getStartGameEvent() {
- // TODO Auto-generated method stub
- return null;
+ return startGameEvent;
}
@Override