From e223b3f99f16df6f5dd3e7e9a5ac5e12bb69086e Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Wed, 8 Feb 2023 16:20:15 +0100 Subject: [PATCH] Update Methode void BuildGui and class NewGameListener --- src/main/java/BattleShip/BShip.java | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/BShip.java b/src/main/java/BattleShip/BShip.java index 772e89d..57d1df7 100644 --- a/src/main/java/BattleShip/BShip.java +++ b/src/main/java/BattleShip/BShip.java @@ -12,11 +12,13 @@ public class BShip { JPanel textPanel = new JPanel(); JTextArea textArea = new JTextArea(); JFrame theFrame = new JFrame("Battleship"); + public boolean autoPlacement = false; JMenuItem auto; JMenuItem[] boardSize = new JMenuItem[3]; public AIGridGUI grid2; int rows = 10; int columns = 10; + boolean shipsPlaced = false; public void startGame() { @@ -28,6 +30,16 @@ public class BShip { grid2 = new AIGridGUI(rows, columns); buildGUI(); + + //Place ships on grid 2. + + if(autoPlacement) { + grid2.autoPlaceShips(); + } else { + grid2.placeShips(); + } + + //.. } public void buildGUI() { @@ -78,7 +90,14 @@ public class BShip { } public class NewGameListener implements ActionListener { - public void actionPerformed(ActionEvent a) {} + public void actionPerformed(ActionEvent a) { + + thePanel.remove(grid1); + thePanel.remove(grid2); + grid1 = null; + grid2 = null; + shipsPlaced = false; + } } }