From cd138ac8978f3d459256df77fc989deeb46dd890 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:44:26 +0100 Subject: [PATCH] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 03c5596..db4a1a2 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -443,7 +443,8 @@ public class AIGridGUI extends JPanel { } public void mouseReleased(MouseEvent e) { - + //If mouse released on cell clear for ship placement, place ship and mark appropriater cells. + BSButton cell = (BSButton) e.getSource(); } public void mouseExited(MouseEvent e) { @@ -457,5 +458,15 @@ public class AIGridGUI extends JPanel { BSButton cell = b; int actionToTake = x; clear = true; + + //Check whether sufficient spaces are clear to place the ship. + if(vertical) { + for(int i = 0; i < shipToPlace.getLength(); i++) { + int testing = cell.getGridLocation() + (i * columns); + if(testing > (rows * columns) || buttons.get(testing).getCellContents() != null) { + clear = false; + } + } + } } }