summaryrefslogtreecommitdiffstats
path: root/src/jrummikub
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub')
-rw-r--r--src/jrummikub/control/ApplicationControl.java16
-rw-r--r--src/jrummikub/control/GameControl.java35
-rw-r--r--src/jrummikub/control/SettingsControl.java101
-rw-r--r--src/jrummikub/view/IView.java4
-rw-r--r--src/jrummikub/view/impl/View.java10
-rw-r--r--src/jrummikub/view/impl/WinPanel.java52
6 files changed, 150 insertions, 68 deletions
diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java
index 7a3113f..582a08c 100644
--- a/src/jrummikub/control/ApplicationControl.java
+++ b/src/jrummikub/control/ApplicationControl.java
@@ -1,6 +1,11 @@
package jrummikub.control;
+import java.util.ArrayList;
+import java.util.List;
+
import jrummikub.model.GameSettings;
+import jrummikub.util.Connection;
+import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.view.IView;
@@ -25,12 +30,21 @@ public class ApplicationControl {
* Starts the application by showing the game settings dialog panel
*/
public void startApplication() {
- SettingsControl settingsControl = new SettingsControl(view, new GameSettings());
+ view.showScorePanel(false);
+ view.enableWinPanel(false);
+ SettingsControl settingsControl = new SettingsControl(view,
+ new GameSettings());
settingsControl.getStartGameEvent().add(new IListener1<GameSettings>() {
@Override
public void handle(GameSettings settings) {
GameControl gameControl = new GameControl(settings, view);
+ gameControl.getEndOfGameEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ startApplication();
+ }
+ });
gameControl.startGame();
}
diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java
index 887b80d..9e967c4 100644
--- a/src/jrummikub/control/GameControl.java
+++ b/src/jrummikub/control/GameControl.java
@@ -9,6 +9,8 @@ import jrummikub.model.IRoundState;
import jrummikub.model.RoundState;
import jrummikub.model.Score;
import jrummikub.util.Connection;
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
import jrummikub.util.IListener;
import jrummikub.util.IListener1;
import jrummikub.view.IView;
@@ -22,14 +24,15 @@ public class GameControl {
RoundControl roundControl;
private GameState gameState;
private List<Connection> connections = new ArrayList<Connection>();
+ private Event endOfGameEvent = new Event();
/**
* Constructor
*
* @param gameSettings
- * the game settings
+ * the game settings
* @param view
- * the view
+ * the view
*/
public GameControl(GameSettings gameSettings, IView view) {
this.gameSettings = gameSettings;
@@ -45,14 +48,33 @@ public class GameControl {
startRound();
}
}));
- connections.add(view.getFinalScoreEvent().add(new IListener() {
+
+ connections.add(view.getNewGameEvent().add(new IListener() {
+ @Override
+ public void handle() {
+ endGame();
+ }
+ }));
+
+ connections.add(view.getEndProgramEvent().add(new IListener() {
@Override
public void handle() {
- finalScore();
+ endProgram();
}
}));
}
+ public IEvent getEndOfGameEvent() {
+ return endOfGameEvent;
+ }
+
+ private void endGame() {
+ for (Connection c : connections) {
+ c.remove();
+ }
+ endOfGameEvent.emit();
+ }
+
/**
* Game gets started by initializing the first Round
*/
@@ -105,12 +127,13 @@ public class GameControl {
view.getScorePanel().setPlayers(gameSettings.getPlayerList());
view.getScorePanel().setScores(gameState.getScores());
- view.getScorePanel().setAccumulatedScore(gameState.getAccumulatedScore());
+ view.getScorePanel().setAccumulatedScore(
+ gameState.getAccumulatedScore());
view.getScorePanel().update();
view.showScorePanel(true);
}
- private void finalScore() {
+ private void endProgram() {
System.exit(0);
}
diff --git a/src/jrummikub/control/SettingsControl.java b/src/jrummikub/control/SettingsControl.java
index 42d3659..dfaa552 100644
--- a/src/jrummikub/control/SettingsControl.java
+++ b/src/jrummikub/control/SettingsControl.java
@@ -1,9 +1,12 @@
package jrummikub.control;
import java.awt.Color;
+import java.util.ArrayList;
+import java.util.List;
import jrummikub.model.GameSettings;
import jrummikub.model.PlayerSettings;
+import jrummikub.util.Connection;
import jrummikub.util.Event1;
import jrummikub.util.IEvent1;
import jrummikub.util.IListener;
@@ -18,6 +21,7 @@ import jrummikub.view.IView;
public class SettingsControl {
private IView view;
private Event1<GameSettings> startGameEvent = new Event1<GameSettings>();
+ private List<Connection> connections = new ArrayList<Connection>();
private GameSettings settings;
@@ -25,9 +29,9 @@ public class SettingsControl {
* Create a new settings control
*
* @param view
- * the view to use
+ * the view to use
* @param settings
- * initial game settings
+ * initial game settings
*/
public SettingsControl(IView view, GameSettings settings) {
this.view = view;
@@ -37,8 +41,8 @@ public class SettingsControl {
}
/**
- * the start game event is emitted when the user wants to start a game and the
- * settings made are valid
+ * the start game event is emitted when the user wants to start a game and
+ * the settings made are valid
*
* @return the event
*/
@@ -50,64 +54,70 @@ public class SettingsControl {
* Start the operation of the settings control
*/
public void startSettings() {
- view.getSettingsPanel().setInitialMeldThreshold(settings.getInitialMeldThreshold());
+ view.getSettingsPanel().setInitialMeldThreshold(
+ settings.getInitialMeldThreshold());
view.getSettingsPanel().setJokerNumber(settings.getJokerNumber());
-
- view.getSettingsPanel().getChangeInitialMeldThresholdEvent().add(new IListener1<Integer>() {
- @Override
- public void handle(Integer value) {
- settings.setInitialMeldThreshold(value);
- update();
- }
- });
-
- view.getSettingsPanel().getChangeJokerNumberEvent().add(new IListener1<Integer>() {
- @Override
- public void handle(Integer value) {
- settings.setJokerNumber(value);
- update();
- }
- });
-
+
+ connections.add(view.getSettingsPanel()
+ .getChangeInitialMeldThresholdEvent()
+ .add(new IListener1<Integer>() {
+ @Override
+ public void handle(Integer value) {
+ settings.setInitialMeldThreshold(value);
+ update();
+ }
+ }));
+
+ connections.add(view.getSettingsPanel().getChangeJokerNumberEvent()
+ .add(new IListener1<Integer>() {
+ @Override
+ public void handle(Integer value) {
+ settings.setJokerNumber(value);
+ update();
+ }
+ }));
+
addPlayerSettingsListeners();
view.showSettingsPanel(true);
}
private void addPlayerSettingsListeners() {
- view.getSettingsPanel().getStartGameEvent().add(new IListener() {
- @Override
- public void handle() {
- startGame();
- }
- });
- view.getSettingsPanel().getAddPlayerEvent().add(new IListener() {
- @Override
- public void handle() {
- addPlayer();
- }
- });
- view.getSettingsPanel().getRemovePlayerEvent()
+ connections.add(view.getSettingsPanel().getStartGameEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ startGame();
+ }
+ }));
+ connections.add(view.getSettingsPanel().getAddPlayerEvent()
+ .add(new IListener() {
+ @Override
+ public void handle() {
+ addPlayer();
+ }
+ }));
+ connections.add(view.getSettingsPanel().getRemovePlayerEvent()
.add(new IListener1<Integer>() {
@Override
public void handle(Integer i) {
removePlayer(i);
}
- });
- view.getSettingsPanel().getChangePlayerColorEvent()
+ }));
+ connections.add(view.getSettingsPanel().getChangePlayerColorEvent()
.add(new IListener2<Integer, Color>() {
@Override
public void handle(Integer i, Color color) {
setPlayerColor(i, color);
}
- });
- view.getSettingsPanel().getChangePlayerNameEvent()
+ }));
+ connections.add(view.getSettingsPanel().getChangePlayerNameEvent()
.add(new IListener2<Integer, String>() {
@Override
public void handle(Integer i, String name) {
setPlayerName(i, name);
}
- });
+ }));
}
private void addPlayer() {
@@ -142,7 +152,8 @@ public class SettingsControl {
break;
}
- settings.getPlayerList().add(new PlayerSettings("Spieler " + num, color));
+ settings.getPlayerList().add(
+ new PlayerSettings("Spieler " + num, color));
update();
}
@@ -178,8 +189,9 @@ public class SettingsControl {
private void update() {
view.getSettingsPanel().enableRemovePlayerButtons(
settings.getPlayerList().size() > 2);
- view.getSettingsPanel().enableAddPlayerButton(
- settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
+ view.getSettingsPanel()
+ .enableAddPlayerButton(
+ settings.getPlayerList().size() < ISettingsPanel.PLAYER_COLORS.length);
checkSettings();
@@ -220,6 +232,9 @@ public class SettingsControl {
view.showSettingsPanel(false);
+ for (Connection c : connections) {
+ c.remove();
+ }
startGameEvent.emit(settings);
}
}
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index 21aa173..b1241c7 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -87,7 +87,7 @@ public interface IView {
*
* @return the event
*/
- public IEvent getFinalScoreEvent();
+ public IEvent getEndProgramEvent();
/**
* The new round event is emitted when the player wants to start a new round
@@ -115,4 +115,6 @@ public interface IView {
public void setCurrentPlayerColor(Color color);
public void setHasLaidOut(boolean hasLaidOut);
+
+ IEvent getNewGameEvent();
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 184155f..b2ae7fb 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -205,7 +205,13 @@ public class View extends JFrame implements IView {
}
@Override
- public IEvent getFinalScoreEvent() {
- return winPanel.getFinalScoreEvent();
+ public IEvent getNewGameEvent() {
+ return winPanel.getNewGameEvent();
}
+
+ @Override
+ public IEvent getEndProgramEvent() {
+ return winPanel.getEndProgramEvent();
+ }
+
}
diff --git a/src/jrummikub/view/impl/WinPanel.java b/src/jrummikub/view/impl/WinPanel.java
index 13a7eb4..61f6e05 100644
--- a/src/jrummikub/view/impl/WinPanel.java
+++ b/src/jrummikub/view/impl/WinPanel.java
@@ -27,9 +27,11 @@ class WinPanel extends JPanel {
private JLabel winLabel;
private JButton newRoundButton;
- private JButton finalScoreButton;
+ private JButton newGameButton;
+ private JButton endProgramButton;
- private Event finalScoreEvent = new Event();
+ private Event endProgramEvent = new Event();
+ private Event newGameEvent = new Event();
private Event newRoundEvent = new Event();
/**
@@ -56,14 +58,23 @@ class WinPanel extends JPanel {
});
add(newRoundButton);
- finalScoreButton = new JButton("Endauswertung");
- finalScoreButton.addActionListener(new ActionListener() {
+ newGameButton = new JButton("Neues Spiel");
+ newGameButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
- finalScoreEvent.emit();
+ newGameEvent.emit();
}
});
- add(finalScoreButton);
+ add(newGameButton);
+
+ endProgramButton = new JButton("Programm verlassen");
+ endProgramButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ endProgramEvent.emit();
+ }
+ });
+ add(endProgramButton);
addComponentListener(new ComponentAdapter() {
@Override
@@ -77,7 +88,7 @@ class WinPanel extends JPanel {
* Sets the name of the current player
*
* @param name
- * the player name
+ * the player name
*/
void setCurrentPlayerName(String name) {
winLabel.setText("Du hast gewonnen, " + name + "!");
@@ -92,19 +103,24 @@ class WinPanel extends JPanel {
return newRoundEvent;
}
+ IEvent getNewGameEvent() {
+ return newGameEvent;
+ }
+
/**
- * The quit event is emitted when the player wants to quit the program
+ * The end program is emitted when the player wants to quit the program
*
* @return the event
*/
- IEvent getFinalScoreEvent() {
- return finalScoreEvent;
+ IEvent getEndProgramEvent() {
+ return endProgramEvent;
}
private void rescale() {
Insets insets = getInsets();
int x = insets.left, y = insets.top, width = getWidth() - insets.left
- - insets.right, height = getHeight() - insets.top - insets.bottom;
+ - insets.right, height = getHeight() - insets.top
+ - insets.bottom;
if (width > PANEL_MAX_WIDTH) {
x += (width - PANEL_MAX_WIDTH) / 4;
@@ -112,7 +128,7 @@ class WinPanel extends JPanel {
}
int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT);
- int buttonWidth = (width - PANEL_SEPARATOR) / 2;
+ int buttonWidth = (width - 2 * PANEL_SEPARATOR) / 3;
int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight;
float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
if (fontSize > MAX_BUTTON_FONT_SIZE)
@@ -123,8 +139,14 @@ class WinPanel extends JPanel {
buttonWidth, buttonHeight);
newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize));
- finalScoreButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y + firstLineHeight
- + PANEL_SEPARATOR, buttonWidth, buttonHeight);
- finalScoreButton.setFont(finalScoreButton.getFont().deriveFont(fontSize));
+ newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y
+ + firstLineHeight + PANEL_SEPARATOR, buttonWidth, buttonHeight);
+ newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize));
+
+ endProgramButton.setBounds(x + 2 * (buttonWidth + PANEL_SEPARATOR), y
+ + firstLineHeight + PANEL_SEPARATOR, buttonWidth, buttonHeight);
+ endProgramButton.setFont(endProgramButton.getFont()
+ .deriveFont(fontSize));
+
}
}