From 2d198820a9634c30d62c77f6f310aa227ee29733 Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Fri, 27 May 2011 17:54:46 +0200 Subject: GameControl tests, temporary handler in SettingsControl and small fixes git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@288 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/GameControl.java | 15 ++++++++++++++- src/jrummikub/control/RoundControl.java | 22 ++++++++++++---------- src/jrummikub/control/SettingsControl.java | 16 +++++++++++++++- src/jrummikub/control/TurnControl.java | 27 ++++++++++++++++++++++++--- src/jrummikub/view/impl/SettingsPanel.java | 16 ++++------------ 5 files changed, 69 insertions(+), 27 deletions(-) (limited to 'src/jrummikub') 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 connections = new ArrayList(); @@ -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(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 selectedStones = new ArrayList(); private Event endOfTurnEvent = new Event(); + private Event redealEvent = new Event(); private List connections = new ArrayList(); 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 playerSettingsPanels = new LinkedList(); private Event1 settingsChangeEvent = new Event1(); - private Event1 startGameEvent = new Event1(); - - /* - * @Override public IEvent1 getSettingsChangeEvent() { return - * settingsChangeEvent; } - * - * @Override public IEvent1 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 -- cgit v1.2.3