From 587d88f764b72f0255d10c0227a81f2a46169ebd Mon Sep 17 00:00:00 2001 From: Kaver Date: Sat, 14 Dec 2024 16:47:12 +0100 Subject: [PATCH] =?UTF-8?q?Reset=20Button=20Funktionalit=C3=A4t=20hinzugef?= =?UTF-8?q?uegt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BoardDisplay.java | 9 +++++++++ src/GameBoard.java | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/src/BoardDisplay.java b/src/BoardDisplay.java index 4941f7f..af7975b 100644 --- a/src/BoardDisplay.java +++ b/src/BoardDisplay.java @@ -92,6 +92,15 @@ public class BoardDisplay extends JPanel { this.currentShip = ship; } + public void resetAllShips() { + ships.clear(); + this.currentShip = null; + for(int i = 0; i < gridSize; i++) { + for(int j = 0; j < gridSize; j++) { + fields[i][j].setBackground(Color.BLUE); + } + } + } /** * TODO Funktion beschreiben etc. * @param ship diff --git a/src/GameBoard.java b/src/GameBoard.java index 3e90032..f65b101 100644 --- a/src/GameBoard.java +++ b/src/GameBoard.java @@ -136,6 +136,13 @@ public class GameBoard extends JPanel { JToggleButton leftPlayerModul7 = new JToggleButton("Reset"); leftPlayerModul7.setBackground(Color.RED); leftButtonsPanel.add(leftPlayerModul7); + + leftPlayerModul7.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + ownBoardPanel.resetAllShips(); + } + }); // Panel für die Buttons des rechten Spielers (ganz rechts) //JPanel ownBoardPanel = new JPanel(new GridLayout(gridSize, gridSize));