From 32447ac27a5875e8f7cab0637b52a2ed2c6d87c4 Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Tue, 21 Dec 2021 14:29:27 +0100 Subject: [PATCH 01/11] gameexplorer: added new class player --- .../java/de/tims/gameexplorer/Player.java | 20 +++++++++++++ .../java/de/tims/gameexplorer/PlayerTest.java | 28 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 src/main/java/de/tims/gameexplorer/Player.java create mode 100644 src/test/java/de/tims/gameexplorer/PlayerTest.java diff --git a/src/main/java/de/tims/gameexplorer/Player.java b/src/main/java/de/tims/gameexplorer/Player.java new file mode 100644 index 0000000..b0d8f52 --- /dev/null +++ b/src/main/java/de/tims/gameexplorer/Player.java @@ -0,0 +1,20 @@ +package de.tims.gameexplorer; + +public class Player { + + private int points; + + public Player(int points) { + this.points = points; + } + + public void addPoints(int pointsToAdd) { + // TODO Auto-generated method stub + + } + + public int getPoints() { + return this.points; + } + +} diff --git a/src/test/java/de/tims/gameexplorer/PlayerTest.java b/src/test/java/de/tims/gameexplorer/PlayerTest.java new file mode 100644 index 0000000..2864ecf --- /dev/null +++ b/src/test/java/de/tims/gameexplorer/PlayerTest.java @@ -0,0 +1,28 @@ +package de.tims.gameexplorer; + +import static org.assertj.core.api.Assertions.*; + +import java.util.stream.Stream; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +class PlayerTest { + + Player player; + + @ParameterizedTest + @MethodSource("testCasesForAddPoints") + void test(String testName, int pointsBefore, int pointsToAdd, int expectedResult) { + player = new Player(pointsBefore); + player.addPoints(pointsToAdd); + int calculatedResult = player.getPoints(); + assertThat(calculatedResult).describedAs(testName).isEqualTo(expectedResult); + } + + private static Stream testCasesForAddPoints() { + return Stream.of(Arguments.of("NoPointsBeforeGet0Points", 0, 0, 0)); + } + +} From ba3a74edb3b279db7f925dbd27c0c38740f152a9 Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Tue, 21 Dec 2021 14:34:29 +0100 Subject: [PATCH 02/11] gameexplorer: addPoints() overrides points of player --- src/main/java/de/tims/gameexplorer/Player.java | 3 +-- src/test/java/de/tims/gameexplorer/PlayerTest.java | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/tims/gameexplorer/Player.java b/src/main/java/de/tims/gameexplorer/Player.java index b0d8f52..34ede76 100644 --- a/src/main/java/de/tims/gameexplorer/Player.java +++ b/src/main/java/de/tims/gameexplorer/Player.java @@ -9,8 +9,7 @@ public class Player { } public void addPoints(int pointsToAdd) { - // TODO Auto-generated method stub - + this.points = pointsToAdd; } public int getPoints() { diff --git a/src/test/java/de/tims/gameexplorer/PlayerTest.java b/src/test/java/de/tims/gameexplorer/PlayerTest.java index 2864ecf..2711727 100644 --- a/src/test/java/de/tims/gameexplorer/PlayerTest.java +++ b/src/test/java/de/tims/gameexplorer/PlayerTest.java @@ -22,7 +22,8 @@ class PlayerTest { } private static Stream testCasesForAddPoints() { - return Stream.of(Arguments.of("NoPointsBeforeGet0Points", 0, 0, 0)); + return Stream.of(Arguments.of("NoPointsBeforeGet0Points", 0, 0, 0), + Arguments.of("NoPointsBeforeGet10Points", 0, 10, 10)); } } From 65ddcbbe1fde97e47285ad9fd26e4fe0b743c5ed Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Tue, 21 Dec 2021 14:39:47 +0100 Subject: [PATCH 03/11] gameexplorer: addPoints() increases / decreases points of player --- src/main/java/de/tims/gameexplorer/Player.java | 2 +- src/test/java/de/tims/gameexplorer/PlayerTest.java | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/gameexplorer/Player.java b/src/main/java/de/tims/gameexplorer/Player.java index 34ede76..4bae8ab 100644 --- a/src/main/java/de/tims/gameexplorer/Player.java +++ b/src/main/java/de/tims/gameexplorer/Player.java @@ -9,7 +9,7 @@ public class Player { } public void addPoints(int pointsToAdd) { - this.points = pointsToAdd; + this.points += pointsToAdd; } public int getPoints() { diff --git a/src/test/java/de/tims/gameexplorer/PlayerTest.java b/src/test/java/de/tims/gameexplorer/PlayerTest.java index 2711727..716245b 100644 --- a/src/test/java/de/tims/gameexplorer/PlayerTest.java +++ b/src/test/java/de/tims/gameexplorer/PlayerTest.java @@ -23,7 +23,9 @@ class PlayerTest { private static Stream testCasesForAddPoints() { return Stream.of(Arguments.of("NoPointsBeforeGet0Points", 0, 0, 0), - Arguments.of("NoPointsBeforeGet10Points", 0, 10, 10)); + Arguments.of("NoPointsBeforeGet10Points", 0, 10, 10), + Arguments.of("10PointsBeforeAdd10Points", 10, 10, 20), + Arguments.of("10PointsBeforeLose10Points", 10, -10, 0)); } } From 8a5ba92d528c33a7bc09aa768740fb353e898af2 Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Wed, 22 Dec 2021 16:42:00 +0100 Subject: [PATCH 04/11] gameexplorer: points cant be less than zero --- src/main/java/de/tims/gameexplorer/Player.java | 2 +- src/test/java/de/tims/gameexplorer/PlayerTest.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/gameexplorer/Player.java b/src/main/java/de/tims/gameexplorer/Player.java index 4bae8ab..0200dc8 100644 --- a/src/main/java/de/tims/gameexplorer/Player.java +++ b/src/main/java/de/tims/gameexplorer/Player.java @@ -9,7 +9,7 @@ public class Player { } public void addPoints(int pointsToAdd) { - this.points += pointsToAdd; + this.points = (this.points + pointsToAdd > 0) ? this.points + pointsToAdd : 0; } public int getPoints() { diff --git a/src/test/java/de/tims/gameexplorer/PlayerTest.java b/src/test/java/de/tims/gameexplorer/PlayerTest.java index 716245b..2d782d1 100644 --- a/src/test/java/de/tims/gameexplorer/PlayerTest.java +++ b/src/test/java/de/tims/gameexplorer/PlayerTest.java @@ -25,7 +25,8 @@ class PlayerTest { return Stream.of(Arguments.of("NoPointsBeforeGet0Points", 0, 0, 0), Arguments.of("NoPointsBeforeGet10Points", 0, 10, 10), Arguments.of("10PointsBeforeAdd10Points", 10, 10, 20), - Arguments.of("10PointsBeforeLose10Points", 10, -10, 0)); + Arguments.of("10PointsBeforeLose10Points", 10, -10, 0), + Arguments.of("LoseMorePointsThanYouHave", 10, -20, 0)); } } From cafb60008f54686ed82da9a8cd972d55232099ac Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Wed, 22 Dec 2021 17:16:33 +0100 Subject: [PATCH 05/11] gameexplorer: added gui --- .../de/tims/gameexplorer/GameExplorer.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/main/java/de/tims/gameexplorer/GameExplorer.java diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java new file mode 100644 index 0000000..3ca8927 --- /dev/null +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -0,0 +1,39 @@ +package de.tims.gameexplorer; + +import javax.swing.*; + +public class GameExplorer { + + private JFrame frame; + private JPanel explorerPanel; + private JButton fleetstormBtn; + private JButton fourwinsBtn; + private JButton tictactoeBtn; + private JButton leaderboardBtn; + + public GameExplorer() { + frame = new JFrame("1000 infomagische Spiele"); + + explorerPanel = new JPanel(); + + fleetstormBtn = new JButton("Schiffe versenken"); + fourwinsBtn = new JButton("Vier gewinnt"); + tictactoeBtn = new JButton("TicTacToe"); + leaderboardBtn = new JButton("Leaderboard"); + + explorerPanel.add(fleetstormBtn); + explorerPanel.add(fourwinsBtn); + explorerPanel.add(tictactoeBtn); + explorerPanel.add(leaderboardBtn); + + frame.add(explorerPanel); + + frame.setSize(640, 480); + frame.setResizable(true); + frame.setVisible(true); + } + + public static void main(String[] args) { + new GameExplorer(); + } +} From 081dc19237a536056e578923fc3a704138dcc821 Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Thu, 23 Dec 2021 16:42:53 +0100 Subject: [PATCH 06/11] gameexplorer: added gui layout --- .../de/tims/gameexplorer/GameExplorer.java | 79 ++++++++++++++++++- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java index 3ca8927..e77b246 100644 --- a/src/main/java/de/tims/gameexplorer/GameExplorer.java +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -1,33 +1,104 @@ package de.tims.gameexplorer; +import java.awt.*; import javax.swing.*; public class GameExplorer { private JFrame frame; private JPanel explorerPanel; + private JPanel border1; + private JPanel border2; + private JPanel border3; + private JPanel border4; + private JPanel border5; private JButton fleetstormBtn; private JButton fourwinsBtn; private JButton tictactoeBtn; private JButton leaderboardBtn; + private Dimension minSize; + private Dimension btnSize; + private GridBagConstraints gbc; public GameExplorer() { frame = new JFrame("1000 infomagische Spiele"); + + minSize = new Dimension(400, 300); + btnSize = new Dimension(160, 40); + gbc = new GridBagConstraints(); explorerPanel = new JPanel(); + explorerPanel.setLayout(new GridBagLayout()); fleetstormBtn = new JButton("Schiffe versenken"); + fleetstormBtn.setPreferredSize(btnSize); fourwinsBtn = new JButton("Vier gewinnt"); + fourwinsBtn.setPreferredSize(btnSize); tictactoeBtn = new JButton("TicTacToe"); + tictactoeBtn.setPreferredSize(btnSize); leaderboardBtn = new JButton("Leaderboard"); + leaderboardBtn.setPreferredSize(btnSize); + + border1 = new JPanel(); + border1.setOpaque(false); + border2 = new JPanel(); + border2.setOpaque(false); + border3 = new JPanel(); + border3.setOpaque(false); + border4 = new JPanel(); + border4.setOpaque(false); + border5 = new JPanel(); + border5.setOpaque(false); + + gbc.gridx = 0; + gbc.gridy = 0; + gbc.weighty = 0.2; + explorerPanel.add(border1, gbc); + + gbc.gridx = 0; + gbc.gridy = 1; + gbc.weighty = 0.0; + explorerPanel.add(fleetstormBtn, gbc); + + gbc.gridx = 0; + gbc.gridy = 2; + gbc.weighty = 0.2; + explorerPanel.add(border2, gbc); - explorerPanel.add(fleetstormBtn); - explorerPanel.add(fourwinsBtn); - explorerPanel.add(tictactoeBtn); - explorerPanel.add(leaderboardBtn); + gbc.gridx = 0; + gbc.gridy = 3; + gbc.weighty = 0.0; + explorerPanel.add(fourwinsBtn, gbc); + + gbc.gridx = 0; + gbc.gridy = 4; + gbc.weighty = 0.2; + explorerPanel.add(border3, gbc); + + gbc.gridx = 0; + gbc.gridy = 5; + gbc.weighty = 0.0; + explorerPanel.add(tictactoeBtn, gbc); + + gbc.gridx = 0; + gbc.gridy = 6; + gbc.weighty = 0.2; + explorerPanel.add(border4, gbc); + + gbc.gridx = 0; + gbc.gridy = 7; + gbc.weighty = 0.0; + explorerPanel.add(leaderboardBtn, gbc); + gbc.gridx = 0; + gbc.gridy = 8; + gbc.weighty = 0.2; + explorerPanel.add(border5, gbc); + frame.add(explorerPanel); + frame.setMinimumSize(minSize); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(640, 480); frame.setResizable(true); frame.setVisible(true); From cd0ddb7a486a660527513dfc78a893c3eccf2553 Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Mon, 27 Dec 2021 16:27:37 +0100 Subject: [PATCH 07/11] gameexplorer: added navigation panel + refactoring --- .../de/tims/gameexplorer/GameExplorer.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java index e77b246..f174d1f 100644 --- a/src/main/java/de/tims/gameexplorer/GameExplorer.java +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -7,6 +7,7 @@ public class GameExplorer { private JFrame frame; private JPanel explorerPanel; + private JPanel navigationPanel; private JPanel border1; private JPanel border2; private JPanel border3; @@ -16,6 +17,8 @@ public class GameExplorer { private JButton fourwinsBtn; private JButton tictactoeBtn; private JButton leaderboardBtn; + private JButton backBtn; + private JLabel chosenGame; private Dimension minSize; private Dimension btnSize; private GridBagConstraints gbc; @@ -27,6 +30,19 @@ public class GameExplorer { btnSize = new Dimension(160, 40); gbc = new GridBagConstraints(); + buildExplorerPanel(); + buildNavigationPanel(); + + frame.add(explorerPanel); + + frame.setMinimumSize(minSize); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(640, 480); + frame.setResizable(true); + frame.setVisible(true); + } + + private void buildExplorerPanel() { explorerPanel = new JPanel(); explorerPanel.setLayout(new GridBagLayout()); @@ -94,14 +110,17 @@ public class GameExplorer { gbc.gridy = 8; gbc.weighty = 0.2; explorerPanel.add(border5, gbc); + } + + private void buildNavigationPanel() { + navigationPanel = new JPanel(); - frame.add(explorerPanel); + backBtn = new JButton("< Zurück"); - frame.setMinimumSize(minSize); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(640, 480); - frame.setResizable(true); - frame.setVisible(true); + chosenGame = new JLabel(); + + navigationPanel.add(backBtn); + navigationPanel.add(chosenGame); } public static void main(String[] args) { From 5903ad63755ffe90ca42577b5fe38c343ffc38fb Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Mon, 27 Dec 2021 16:34:52 +0100 Subject: [PATCH 08/11] gameexplorer: added layout for navigation panel --- .../de/tims/gameexplorer/GameExplorer.java | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java index f174d1f..9e78247 100644 --- a/src/main/java/de/tims/gameexplorer/GameExplorer.java +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -13,6 +13,7 @@ public class GameExplorer { private JPanel border3; private JPanel border4; private JPanel border5; + private JPanel border6; private JButton fleetstormBtn; private JButton fourwinsBtn; private JButton tictactoeBtn; @@ -114,13 +115,33 @@ public class GameExplorer { private void buildNavigationPanel() { navigationPanel = new JPanel(); + navigationPanel.setLayout(new GridBagLayout()); backBtn = new JButton("< Zurück"); chosenGame = new JLabel(); - navigationPanel.add(backBtn); - navigationPanel.add(chosenGame); + border6 = new JPanel(); + border6.setOpaque(false); + + gbc.weighty = 0.0; + gbc.gridx = 0; + gbc.gridy = 0; + gbc.weightx = 0.0; + gbc.insets = new Insets(5, 20, 5, 0); + navigationPanel.add(backBtn, gbc); + + gbc.gridx = 1; + gbc.gridy = 0; + gbc.weightx = 1.0; + gbc.insets = new Insets(0, 0, 0, 0); + navigationPanel.add(border6, gbc); + + gbc.gridx = 2; + gbc.gridy = 0; + gbc.weightx = 0.0; + gbc.insets = new Insets(5, 0, 5, 20); + navigationPanel.add(chosenGame, gbc); } public static void main(String[] args) { From 52b0f2d064c0ce88336e0bb63806f22f3afa044e Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Mon, 27 Dec 2021 17:09:16 +0100 Subject: [PATCH 09/11] gameexplorer: added game panel --- src/main/java/de/tims/gameexplorer/GameExplorer.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java index 9e78247..3c15004 100644 --- a/src/main/java/de/tims/gameexplorer/GameExplorer.java +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -7,6 +7,7 @@ public class GameExplorer { private JFrame frame; private JPanel explorerPanel; + private JPanel gamePanel; private JPanel navigationPanel; private JPanel border1; private JPanel border2; @@ -33,8 +34,9 @@ public class GameExplorer { buildExplorerPanel(); buildNavigationPanel(); + buildGamePanels(); - frame.add(explorerPanel); + frame.add(gamePanel); frame.setMinimumSize(minSize); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -144,6 +146,13 @@ public class GameExplorer { navigationPanel.add(chosenGame, gbc); } + private void buildGamePanels() { + gamePanel = new JPanel(); + gamePanel.setLayout(new BorderLayout()); + + gamePanel.add(navigationPanel, BorderLayout.PAGE_START); + } + public static void main(String[] args) { new GameExplorer(); } From d2fb0fa2b3be602ca060201efdb4c242bd2ffb58 Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Mon, 27 Dec 2021 17:18:22 +0100 Subject: [PATCH 10/11] gameexplorer: added action listeners for navigation between game and menu --- .../de/tims/gameexplorer/GameExplorer.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java index 3c15004..cde21e3 100644 --- a/src/main/java/de/tims/gameexplorer/GameExplorer.java +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -1,6 +1,7 @@ package de.tims.gameexplorer; import java.awt.*; +import java.awt.event.*; import javax.swing.*; public class GameExplorer { @@ -36,7 +37,7 @@ public class GameExplorer { buildNavigationPanel(); buildGamePanels(); - frame.add(gamePanel); + frame.add(explorerPanel); frame.setMinimumSize(minSize); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -51,12 +52,16 @@ public class GameExplorer { fleetstormBtn = new JButton("Schiffe versenken"); fleetstormBtn.setPreferredSize(btnSize); + fleetstormBtn.addActionListener(new GameAction()); fourwinsBtn = new JButton("Vier gewinnt"); fourwinsBtn.setPreferredSize(btnSize); + fourwinsBtn.addActionListener(new GameAction()); tictactoeBtn = new JButton("TicTacToe"); tictactoeBtn.setPreferredSize(btnSize); + tictactoeBtn.addActionListener(new GameAction()); leaderboardBtn = new JButton("Leaderboard"); leaderboardBtn.setPreferredSize(btnSize); + leaderboardBtn.addActionListener(new GameAction()); border1 = new JPanel(); border1.setOpaque(false); @@ -120,6 +125,7 @@ public class GameExplorer { navigationPanel.setLayout(new GridBagLayout()); backBtn = new JButton("< Zurück"); + backBtn.addActionListener(new BackAction()); chosenGame = new JLabel(); @@ -153,6 +159,26 @@ public class GameExplorer { gamePanel.add(navigationPanel, BorderLayout.PAGE_START); } + private class GameAction implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + frame.remove(explorerPanel); + frame.add(gamePanel); + frame.revalidate(); + frame.repaint(); + } + } + + private class BackAction implements ActionListener { + @Override + public void actionPerformed(ActionEvent e) { + frame.remove(gamePanel); + frame.add(explorerPanel); + frame.revalidate(); + frame.repaint(); + } + } + public static void main(String[] args) { new GameExplorer(); } From 85669e4412c5b2d0138a234a914a8640c223386e Mon Sep 17 00:00:00 2001 From: Tobias Krause Date: Mon, 27 Dec 2021 17:38:14 +0100 Subject: [PATCH 11/11] gameexplorer: each button opens a different (dummy) game panel --- .../de/tims/gameexplorer/GameExplorer.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/main/java/de/tims/gameexplorer/GameExplorer.java b/src/main/java/de/tims/gameexplorer/GameExplorer.java index cde21e3..03c23dd 100644 --- a/src/main/java/de/tims/gameexplorer/GameExplorer.java +++ b/src/main/java/de/tims/gameexplorer/GameExplorer.java @@ -10,6 +10,10 @@ public class GameExplorer { private JPanel explorerPanel; private JPanel gamePanel; private JPanel navigationPanel; + private JPanel fleetstormPanel; + private JPanel fourwinsPanel; + private JPanel tictactoePanel; + private JPanel leaderboardPanel; private JPanel border1; private JPanel border2; private JPanel border3; @@ -26,6 +30,9 @@ public class GameExplorer { private Dimension btnSize; private GridBagConstraints gbc; + private enum Game { FLEETSTORM, FOURWINS, TICTACTOE, LEADERBOARD }; + private Game actualGame; + public GameExplorer() { frame = new JFrame("1000 infomagische Spiele"); @@ -157,11 +164,43 @@ public class GameExplorer { gamePanel.setLayout(new BorderLayout()); gamePanel.add(navigationPanel, BorderLayout.PAGE_START); + + //use of dummy panels because real panels have not been implemented yet + fleetstormPanel = new JPanel(); + fleetstormPanel.setBackground(Color.BLUE); + + fourwinsPanel = new JPanel(); + fourwinsPanel.setBackground(Color.GREEN); + + tictactoePanel = new JPanel(); + tictactoePanel.setBackground(Color.YELLOW); + + leaderboardPanel = new JPanel(); + leaderboardPanel.setBackground(Color.RED); } private class GameAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { + //each button adds a different dummy panel to the gamePanel + if (e.getSource() == fleetstormBtn) { + actualGame = Game.FLEETSTORM; + chosenGame.setText("Schiffe versenken"); + gamePanel.add(fleetstormPanel, BorderLayout.CENTER); + } else if (e.getSource() == fourwinsBtn) { + actualGame = Game.FOURWINS; + chosenGame.setText("Vier gewinnt"); + gamePanel.add(fourwinsPanel, BorderLayout.CENTER); + } else if (e.getSource() == tictactoeBtn) { + actualGame = Game.TICTACTOE; + chosenGame.setText("TicTacToe"); + gamePanel.add(tictactoePanel, BorderLayout.CENTER); + } else if (e.getSource() == leaderboardBtn) { + actualGame = Game.LEADERBOARD; + chosenGame.setText("Leaderboard"); + gamePanel.add(leaderboardPanel, BorderLayout.CENTER); + } + frame.remove(explorerPanel); frame.add(gamePanel); frame.revalidate(); @@ -172,6 +211,20 @@ public class GameExplorer { private class BackAction implements ActionListener { @Override public void actionPerformed(ActionEvent e) { + switch (actualGame) { + case FLEETSTORM: + gamePanel.remove(fleetstormPanel); + break; + case FOURWINS: + gamePanel.remove(fourwinsPanel); + break; + case TICTACTOE: + gamePanel.remove(tictactoePanel); + break; + case LEADERBOARD: + gamePanel.remove(leaderboardPanel); + } + frame.remove(gamePanel); frame.add(explorerPanel); frame.revalidate();