From 70af06e1bff47a36de9d9106412388b2f5b91f15 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Wed, 8 Jun 2011 17:46:44 +0200 Subject: LAden und Speichern geht jetzt immer sauber git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@388 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/ApplicationControl.java | 9 ++-- src/jrummikub/control/GameControl.java | 16 ++++++- src/jrummikub/control/RoundControl.java | 18 ++++++-- src/jrummikub/view/IView.java | 28 +++++++------ src/jrummikub/view/impl/View.java | 60 ++++++++++++++++----------- 5 files changed, 87 insertions(+), 44 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index 068b898..e4ddb55 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -16,6 +16,7 @@ import jrummikub.view.IView.BottomPanelType; public class ApplicationControl { private SaveControl saveControl; private IView view; + private GameControl gameControl; /** * Creates a new application control @@ -53,8 +54,10 @@ public class ApplicationControl { public void handle(GameSettings settings, GameState gameState, IRoundState roundState) { settingsControl.abort(); - // TODO alles ordentlich beenden (controls) - GameControl gameControl = new GameControl(settings, + if (gameControl != null){ + gameControl.abortGame(); + } + gameControl = new GameControl(settings, saveControl, view); addGameControlListeners(gameControl); gameControl.continueGame(gameState, roundState); @@ -67,7 +70,7 @@ public class ApplicationControl { public void handle(GameSettings settings) { saveControl.setGameSettings(settings); - GameControl gameControl = new GameControl(settings, + gameControl = new GameControl(settings, saveControl, view); addGameControlListeners(gameControl); diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java index 985781a..194d0de 100644 --- a/src/jrummikub/control/GameControl.java +++ b/src/jrummikub/control/GameControl.java @@ -83,10 +83,14 @@ public class GameControl { } private void endGame() { + removeListeners(); + endOfGameEvent.emit(); + } + + private void removeListeners() { for (Connection c : connections) { c.remove(); } - endOfGameEvent.emit(); } /** @@ -106,6 +110,16 @@ public class GameControl { } } + public void abortGame() { + removeListeners(); + if (roundControl != null) { + roundControl.abortRound(); + roundControl = null; + } + + view.clearView(); + } + private void startRound() { if (roundControl != null) { return; diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 4fadc15..e1009af 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -84,6 +84,14 @@ public class RoundControl { prepareTurn(); } + public void abortRound() { + removeListeners(); + if (turnControl != null) { + turnControl.abortTurn(); + turnControl = null; + } + } + private void prepareTurn() { boolean isHuman = roundState.getActivePlayer().getPlayerSettings() .getTurnControlType() == HUMAN; @@ -294,14 +302,18 @@ public class RoundControl { } void endOfRound() { - for (Connection c : connections) { - c.remove(); - } + removeListeners(); Score roundScore = score(); endOfRoundEvent.emit(roundScore); roundFinished = true; } + private void removeListeners() { + for (Connection c : connections) { + c.remove(); + } + } + private Score score() { List winners = new ArrayList(); List points = new ArrayList(); diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java index 8280a1b..797c704 100644 --- a/src/jrummikub/view/IView.java +++ b/src/jrummikub/view/IView.java @@ -49,7 +49,7 @@ public interface IView { * Sets the current player's name * * @param playerName - * the player name + * the player name */ public void setCurrentPlayerName(String playerName); @@ -57,7 +57,7 @@ public interface IView { * Sets the stones that are to be painted selected * * @param stones - * the stones to be painted selected + * the stones to be painted selected */ public void setSelectedStones(Collection stones); @@ -86,7 +86,7 @@ public interface IView { * Shows or hides the game settings panel * * @param show - * specifies if the panel shall be shown or hidden + * specifies if the panel shall be shown or hidden */ public void showSettingsPanel(boolean show); @@ -94,7 +94,7 @@ public interface IView { * Shows or hides the score panel * * @param show - * specifies if the panel shall be shown or hidden + * specifies if the panel shall be shown or hidden */ public void showScorePanel(boolean show); @@ -103,16 +103,16 @@ public interface IView { * along with the name * * @param color - * the current player's color + * the current player's color */ public void setCurrentPlayerColor(Color color); /** - * Is used for the PlayerPanel to display if a player has laid out along with - * the name + * Is used for the PlayerPanel to display if a player has laid out along + * with the name * * @param hasLaidOut - * specifies if the current player has laid out or not + * specifies if the current player has laid out or not */ public void setCurrentPlayerHasLaidOut(boolean hasLaidOut); @@ -127,7 +127,7 @@ public interface IView { * Sets the bottom panels type * * @param type - * the type of the bottom panel + * the type of the bottom panel */ public void setBottomPanel(BottomPanelType type); @@ -148,8 +148,8 @@ public interface IView { } /** - * The menu new game event is emitted when the user selects the new game menu - * entry + * The menu new game event is emitted when the user selects the new game + * menu entry * * @return the event */ @@ -168,7 +168,7 @@ public interface IView { * * @return the event */ - IEvent1 getLoadEvent(); + public IEvent1 getLoadEvent(); /** * The save event is emitted when the user wants to save the current game @@ -176,5 +176,7 @@ public interface IView { * * @return the event */ - IEvent1 getSaveEvent(); + public IEvent1 getSaveEvent(); + + public void clearView(); } diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index a3bded6..a6e5efe 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -114,6 +114,17 @@ public class View extends JFrame implements IView { return saveEvent; } + @Override + public void clearView() { + showScorePanel(false); + showSettingsPanel(false); + getHandPanel().setStones( + Collections.> emptyList()); + getTablePanel().setStoneSets( + Collections.> emptyList()); + setSelectedStones(Collections. emptyList()); + } + private void createFileChooser() { chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( @@ -208,8 +219,8 @@ public class View extends JFrame implements IView { mainLayer.add(table); playerPanel = new PlayerPanel(); - playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0, - Color.BLACK)); + playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, + 0, Color.BLACK)); mainLayer.add(playerPanel); startTurnPanel = new StartTurnPanel(); @@ -318,24 +329,24 @@ public class View extends JFrame implements IView { @SuppressWarnings("unchecked") private List> createDecorationStones() { - Pair stoneJ = new Pair(new Stone(-'J', - StoneColor.BLACK), new Position(2.5f, 0)); - Pair stoneR = new Pair(new Stone(-'R', - StoneColor.ORANGE), new Position(3.5f, 0)); - Pair stoneu1 = new Pair(new Stone(-'u', - StoneColor.BLUE), new Position(4.5f, 0)); - Pair stonem1 = new Pair(new Stone(-'m', - StoneColor.RED), new Position(5.5f, 0)); - Pair stonem2 = new Pair(new Stone(-'m', - StoneColor.GREEN), new Position(6.5f, 0)); - Pair stonei = new Pair(new Stone(-'i', - StoneColor.VIOLET), new Position(7.5f, 0)); - Pair stonek = new Pair(new Stone(-'k', - StoneColor.AQUA), new Position(8.5f, 0)); - Pair stoneu2 = new Pair(new Stone(-'u', - StoneColor.GRAY), new Position(9.5f, 0)); - Pair stoneb = new Pair(new Stone(-'b', - StoneColor.BLACK), new Position(10.5f, 0)); + Pair stoneJ = new Pair(new Stone( + -'J', StoneColor.BLACK), new Position(2.5f, 0)); + Pair stoneR = new Pair(new Stone( + -'R', StoneColor.ORANGE), new Position(3.5f, 0)); + Pair stoneu1 = new Pair(new Stone( + -'u', StoneColor.BLUE), new Position(4.5f, 0)); + Pair stonem1 = new Pair(new Stone( + -'m', StoneColor.RED), new Position(5.5f, 0)); + Pair stonem2 = new Pair(new Stone( + -'m', StoneColor.GREEN), new Position(6.5f, 0)); + Pair stonei = new Pair(new Stone( + -'i', StoneColor.VIOLET), new Position(7.5f, 0)); + Pair stonek = new Pair(new Stone( + -'k', StoneColor.AQUA), new Position(8.5f, 0)); + Pair stoneu2 = new Pair(new Stone( + -'u', StoneColor.GRAY), new Position(9.5f, 0)); + Pair stoneb = new Pair(new Stone( + -'b', StoneColor.BLACK), new Position(10.5f, 0)); Pair stone1 = new Pair(new Stone( StoneColor.RED), new Position(2, 1)); @@ -350,9 +361,9 @@ public class View extends JFrame implements IView { Pair stone6 = new Pair(new Stone( StoneColor.BLACK), new Position(11, 1)); - return Arrays - .asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek, - stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6); + return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, + stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4, + stone5, stone6); } @Override @@ -363,7 +374,8 @@ public class View extends JFrame implements IView { && type != BottomPanelType.WIN_PANEL); if (type == BottomPanelType.START_GAME_PANEL) { - table.setStoneSets(Collections.> emptyList()); + table.setStoneSets(Collections + .> emptyList()); playerPanel.getHandPanel().setStones(createDecorationStones()); } -- cgit v1.2.3