LAden und Speichern geht jetzt immer sauber

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@388 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Ida Massow 2011-06-08 17:46:44 +02:00
parent 41fe3c93b3
commit 70af06e1bf
5 changed files with 87 additions and 44 deletions

View file

@ -16,6 +16,7 @@ import jrummikub.view.IView.BottomPanelType;
public class ApplicationControl { public class ApplicationControl {
private SaveControl saveControl; private SaveControl saveControl;
private IView view; private IView view;
private GameControl gameControl;
/** /**
* Creates a new application control * Creates a new application control
@ -53,8 +54,10 @@ public class ApplicationControl {
public void handle(GameSettings settings, public void handle(GameSettings settings,
GameState gameState, IRoundState roundState) { GameState gameState, IRoundState roundState) {
settingsControl.abort(); settingsControl.abort();
// TODO alles ordentlich beenden (controls) if (gameControl != null){
GameControl gameControl = new GameControl(settings, gameControl.abortGame();
}
gameControl = new GameControl(settings,
saveControl, view); saveControl, view);
addGameControlListeners(gameControl); addGameControlListeners(gameControl);
gameControl.continueGame(gameState, roundState); gameControl.continueGame(gameState, roundState);
@ -67,7 +70,7 @@ public class ApplicationControl {
public void handle(GameSettings settings) { public void handle(GameSettings settings) {
saveControl.setGameSettings(settings); saveControl.setGameSettings(settings);
GameControl gameControl = new GameControl(settings, gameControl = new GameControl(settings,
saveControl, view); saveControl, view);
addGameControlListeners(gameControl); addGameControlListeners(gameControl);

View file

@ -83,10 +83,14 @@ public class GameControl {
} }
private void endGame() { private void endGame() {
removeListeners();
endOfGameEvent.emit();
}
private void removeListeners() {
for (Connection c : connections) { for (Connection c : connections) {
c.remove(); 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() { private void startRound() {
if (roundControl != null) { if (roundControl != null) {
return; return;

View file

@ -84,6 +84,14 @@ public class RoundControl {
prepareTurn(); prepareTurn();
} }
public void abortRound() {
removeListeners();
if (turnControl != null) {
turnControl.abortTurn();
turnControl = null;
}
}
private void prepareTurn() { private void prepareTurn() {
boolean isHuman = roundState.getActivePlayer().getPlayerSettings() boolean isHuman = roundState.getActivePlayer().getPlayerSettings()
.getTurnControlType() == HUMAN; .getTurnControlType() == HUMAN;
@ -294,14 +302,18 @@ public class RoundControl {
} }
void endOfRound() { void endOfRound() {
for (Connection c : connections) { removeListeners();
c.remove();
}
Score roundScore = score(); Score roundScore = score();
endOfRoundEvent.emit(roundScore); endOfRoundEvent.emit(roundScore);
roundFinished = true; roundFinished = true;
} }
private void removeListeners() {
for (Connection c : connections) {
c.remove();
}
}
private Score score() { private Score score() {
List<Boolean> winners = new ArrayList<Boolean>(); List<Boolean> winners = new ArrayList<Boolean>();
List<Integer> points = new ArrayList<Integer>(); List<Integer> points = new ArrayList<Integer>();

View file

@ -49,7 +49,7 @@ public interface IView {
* Sets the current player's name * Sets the current player's name
* *
* @param playerName * @param playerName
* the player name * the player name
*/ */
public void setCurrentPlayerName(String playerName); public void setCurrentPlayerName(String playerName);
@ -57,7 +57,7 @@ public interface IView {
* Sets the stones that are to be painted selected * Sets the stones that are to be painted selected
* *
* @param stones * @param stones
* the stones to be painted selected * the stones to be painted selected
*/ */
public void setSelectedStones(Collection<Stone> stones); public void setSelectedStones(Collection<Stone> stones);
@ -86,7 +86,7 @@ public interface IView {
* Shows or hides the game settings panel * Shows or hides the game settings panel
* *
* @param show * @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); public void showSettingsPanel(boolean show);
@ -94,7 +94,7 @@ public interface IView {
* Shows or hides the score panel * Shows or hides the score panel
* *
* @param show * @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); public void showScorePanel(boolean show);
@ -103,16 +103,16 @@ public interface IView {
* along with the name * along with the name
* *
* @param color * @param color
* the current player's color * the current player's color
*/ */
public void setCurrentPlayerColor(Color color); public void setCurrentPlayerColor(Color color);
/** /**
* Is used for the PlayerPanel to display if a player has laid out along with * Is used for the PlayerPanel to display if a player has laid out along
* the name * with the name
* *
* @param hasLaidOut * @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); public void setCurrentPlayerHasLaidOut(boolean hasLaidOut);
@ -127,7 +127,7 @@ public interface IView {
* Sets the bottom panels type * Sets the bottom panels type
* *
* @param type * @param type
* the type of the bottom panel * the type of the bottom panel
*/ */
public void setBottomPanel(BottomPanelType type); 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 * The menu new game event is emitted when the user selects the new game
* entry * menu entry
* *
* @return the event * @return the event
*/ */
@ -168,7 +168,7 @@ public interface IView {
* *
* @return the event * @return the event
*/ */
IEvent1<File> getLoadEvent(); public IEvent1<File> getLoadEvent();
/** /**
* The save event is emitted when the user wants to save the current game * The save event is emitted when the user wants to save the current game
@ -176,5 +176,7 @@ public interface IView {
* *
* @return the event * @return the event
*/ */
IEvent1<File> getSaveEvent(); public IEvent1<File> getSaveEvent();
public void clearView();
} }

View file

@ -114,6 +114,17 @@ public class View extends JFrame implements IView {
return saveEvent; return saveEvent;
} }
@Override
public void clearView() {
showScorePanel(false);
showSettingsPanel(false);
getHandPanel().setStones(
Collections.<Pair<Stone, Position>> emptyList());
getTablePanel().setStoneSets(
Collections.<Pair<StoneSet, Position>> emptyList());
setSelectedStones(Collections.<Stone> emptyList());
}
private void createFileChooser() { private void createFileChooser() {
chooser = new JFileChooser(); chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter( FileNameExtensionFilter filter = new FileNameExtensionFilter(
@ -208,8 +219,8 @@ public class View extends JFrame implements IView {
mainLayer.add(table); mainLayer.add(table);
playerPanel = new PlayerPanel(); playerPanel = new PlayerPanel();
playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0, playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
Color.BLACK)); 0, Color.BLACK));
mainLayer.add(playerPanel); mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel(); startTurnPanel = new StartTurnPanel();
@ -318,24 +329,24 @@ public class View extends JFrame implements IView {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private List<Pair<Stone, Position>> createDecorationStones() { private List<Pair<Stone, Position>> createDecorationStones() {
Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(-'J', Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(2.5f, 0)); -'J', StoneColor.BLACK), new Position(2.5f, 0));
Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(-'R', Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(
StoneColor.ORANGE), new Position(3.5f, 0)); -'R', StoneColor.ORANGE), new Position(3.5f, 0));
Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(-'u', Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(
StoneColor.BLUE), new Position(4.5f, 0)); -'u', StoneColor.BLUE), new Position(4.5f, 0));
Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(-'m', Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(5.5f, 0)); -'m', StoneColor.RED), new Position(5.5f, 0));
Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(-'m', Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(
StoneColor.GREEN), new Position(6.5f, 0)); -'m', StoneColor.GREEN), new Position(6.5f, 0));
Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(-'i', Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(
StoneColor.VIOLET), new Position(7.5f, 0)); -'i', StoneColor.VIOLET), new Position(7.5f, 0));
Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(-'k', Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(
StoneColor.AQUA), new Position(8.5f, 0)); -'k', StoneColor.AQUA), new Position(8.5f, 0));
Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(-'u', Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(
StoneColor.GRAY), new Position(9.5f, 0)); -'u', StoneColor.GRAY), new Position(9.5f, 0));
Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(-'b', Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(10.5f, 0)); -'b', StoneColor.BLACK), new Position(10.5f, 0));
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone( Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(2, 1)); StoneColor.RED), new Position(2, 1));
@ -350,9 +361,9 @@ public class View extends JFrame implements IView {
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone( Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(11, 1)); StoneColor.BLACK), new Position(11, 1));
return Arrays return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei,
.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek, stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4,
stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6); stone5, stone6);
} }
@Override @Override
@ -363,7 +374,8 @@ public class View extends JFrame implements IView {
&& type != BottomPanelType.WIN_PANEL); && type != BottomPanelType.WIN_PANEL);
if (type == BottomPanelType.START_GAME_PANEL) { if (type == BottomPanelType.START_GAME_PANEL) {
table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList()); table.setStoneSets(Collections
.<Pair<StoneSet, Position>> emptyList());
playerPanel.getHandPanel().setStones(createDecorationStones()); playerPanel.getHandPanel().setStones(createDecorationStones());
} }