summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jrummikub/JRummikub.java6
-rw-r--r--src/jrummikub/view/IView.java6
-rw-r--r--src/jrummikub/view/impl/View.java37
-rw-r--r--src/jrummikub/view/impl/WinPanel.java104
4 files changed, 145 insertions, 8 deletions
diff --git a/src/jrummikub/JRummikub.java b/src/jrummikub/JRummikub.java
index 9d32a2f..5bddc68 100644
--- a/src/jrummikub/JRummikub.java
+++ b/src/jrummikub/JRummikub.java
@@ -143,7 +143,7 @@ public class JRummikub {
public void handle(Stone s, Boolean collect) {
System.out.println("Table set-clicked at " + s
+ (collect ? ", collect" : ""));
-
+ view.enableWinPanel(true);
}
});
@@ -195,8 +195,8 @@ public class JRummikub {
// stoneSets on the table
Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
- stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE)), new Position(
- 0.5f, 1));
+ stoneSets.put(new StoneSet(new Stone(5, StoneColor.ORANGE)),
+ new Position(0.5f, 1));
List<Stone> stoneList = new ArrayList<Stone>();
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index b43984b..115308d 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -53,4 +53,10 @@ public interface IView {
* @return the event
*/
public IEvent getStartTurnEvent();
+
+ void enableWinPanel(boolean enable);
+
+ IEvent getQuitEvent();
+
+ IEvent getNewGameEvent();
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index e3d58ea..6300109 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -23,6 +23,7 @@ public class View extends JFrame implements IView {
private TablePanel table;
private PlayerPanel playerPanel;
private StartTurnPanel startTurnPanel;
+ private WinPanel winPanel;
private final static float PLAYER_PANEL_RATIO = 0.14f;
private final static int PLAYER_PANEL_BORDER_WIDTH = 1;
@@ -56,14 +57,18 @@ public class View extends JFrame implements IView {
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));
add(playerPanel);
startTurnPanel = new StartTurnPanel();
startTurnPanel.setVisible(false);
add(startTurnPanel);
+ winPanel = new WinPanel();
+ winPanel.setVisible(false);
+ add(winPanel);
+
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
@@ -71,8 +76,9 @@ public class View extends JFrame implements IView {
int width = getWidth() - insets.left - insets.right, height = getHeight()
- insets.top - insets.bottom;
- int playerPanelHeight = even(Math.pow((double) width * width * height,
- 1 / 3.0) * PLAYER_PANEL_RATIO)
+ int playerPanelHeight = even(Math.pow((double) width * width
+ * height, 1 / 3.0)
+ * PLAYER_PANEL_RATIO)
+ PLAYER_PANEL_BORDER_WIDTH;
if (playerPanelHeight > PLAYER_PANEL_MAX_HEIGHT)
playerPanelHeight = PLAYER_PANEL_MAX_HEIGHT;
@@ -82,7 +88,9 @@ public class View extends JFrame implements IView {
table.setBounds(0, 0, width, tableHeight);
table.validate();
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
- startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
+ startTurnPanel.setBounds(0, tableHeight, width,
+ playerPanelHeight);
+ winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
}
});
@@ -99,6 +107,14 @@ public class View extends JFrame implements IView {
public void enableStartTurnPanel(boolean enable) {
playerPanel.setVisible(!enable);
startTurnPanel.setVisible(enable);
+ winPanel.setVisible(!enable);
+ }
+
+ @Override
+ public void enableWinPanel(boolean enable) {
+ playerPanel.setVisible(!enable);
+ startTurnPanel.setVisible(!enable);
+ winPanel.setVisible(enable);
}
@Override
@@ -111,4 +127,15 @@ public class View extends JFrame implements IView {
public IEvent getStartTurnEvent() {
return startTurnPanel.getStartTurnEvent();
}
+
+ @Override
+ public IEvent getNewGameEvent() {
+ return winPanel.getNewGameEvent();
+ }
+
+ @Override
+ public IEvent getQuitEvent() {
+ return winPanel.getQuitEvent();
+ }
+
}
diff --git a/src/jrummikub/view/impl/WinPanel.java b/src/jrummikub/view/impl/WinPanel.java
new file mode 100644
index 0000000..cd63540
--- /dev/null
+++ b/src/jrummikub/view/impl/WinPanel.java
@@ -0,0 +1,104 @@
+package jrummikub.view.impl;
+
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
+
+public class WinPanel extends JPanel {
+ private final static int PANEL_INSET = 15;
+ private final static int PANEL_SEPARATOR = 10;
+ private final static float PANEL_FIRST_LINE_HEIGHT = 0.375f;
+ private final static int PANEL_MAX_WIDTH = 180;
+ private final static float MAX_BUTTON_FONT_SIZE = 12;
+
+ private JLabel winLabel;
+ private JButton newGameButton;
+ private JButton quitButton;
+
+ private Event quitEvent = new Event();
+ private Event newGameEvent = new Event();
+
+ WinPanel() {
+ setLayout(null);
+ setBorder(new EmptyBorder(PANEL_INSET, PANEL_INSET, PANEL_INSET,
+ PANEL_INSET));
+
+ winLabel = new JLabel("Du hast gewonnen!");
+ winLabel.setHorizontalAlignment(JLabel.CENTER);
+ winLabel.setHorizontalTextPosition(JLabel.CENTER);
+ winLabel.setVerticalAlignment(JLabel.CENTER);
+ winLabel.setVerticalTextPosition(JLabel.CENTER);
+ add(winLabel);
+
+ newGameButton = new JButton("Neues Spiel");
+ newGameButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ newGameEvent.emit();
+ }
+ });
+ add(newGameButton);
+
+ quitButton = new JButton("Beenden");
+ quitButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ quitEvent.emit();
+ }
+ });
+ add(quitButton);
+
+ addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ rescale();
+ }
+ });
+ }
+
+ IEvent getNewGameEvent() {
+ return newGameEvent;
+ }
+
+ IEvent getQuitEvent() {
+ return quitEvent;
+ }
+
+ 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;
+
+ if (width > PANEL_MAX_WIDTH) {
+ x += (width - PANEL_MAX_WIDTH) / 4;
+ width = width / 2 + PANEL_MAX_WIDTH / 2;
+ }
+
+ int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT);
+ int buttonWidth = (width - PANEL_SEPARATOR) / 2;
+ int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight;
+ float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
+ if (fontSize > MAX_BUTTON_FONT_SIZE)
+ fontSize = MAX_BUTTON_FONT_SIZE;
+
+ winLabel.setBounds(x, y, width, firstLineHeight);
+ newGameButton.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR,
+ buttonWidth, buttonHeight);
+ newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize));
+
+ quitButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y
+ + firstLineHeight + PANEL_SEPARATOR, buttonWidth, buttonHeight);
+ quitButton.setFont(quitButton.getFont().deriveFont(fontSize));
+ }
+}