From 3167f700f18f44f6caf91ff1ca09ece111ad9a5d Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:35:46 +0100 Subject: [PATCH] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 34 +++++++++++++++++++++- target/classes/BattleShip/AIGridGUI.class | Bin 6013 -> 9291 bytes 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index f682b1c..845abf4 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -3,13 +3,15 @@ package BattleShip; import javax.swing.*; import javax.swing.border.Border; import java.awt.*; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.*; public class AIGridGUI extends JPanel { ArrayList buttons = new ArrayList(); ArrayList allShips = new ArrayList(); - // public ArrayList listeners = new ArrayList(); + public ArrayList listeners = new ArrayList(); int[] testLocations; int numOfGuesses = 0; @@ -152,6 +154,18 @@ public class AIGridGUI extends JPanel { shipsPlaced = true; } + public void placeShips() { + + //Add listeners to all cells in grid to listen for ship placement. + + for(int i = 0; i < buttons.size(); i++) { + listeners.add(new SetShipsListener()); + buttons.get(i).addMouseListener(listeners.get(i)); + } + + shipToPlace = allShips.get(0); + text = "Place " + shipToPlace.getName() + ". Right click to toggle horizontal/vertical."; + } public boolean getEndGame() { return endGame; @@ -418,4 +432,22 @@ public class AIGridGUI extends JPanel { return ((Integer) two.getCount()).compareTo((Integer) one.getCount()); } } + + //Listen for mouse actions to place ships. + + class SetShipsListener implements MouseListener { + public void mouseEntered(MouseEvent e) { + + } + + public void mouseReleased(MouseEvent e) { + + } + + public void mouseExited(MouseEvent e) { + + } + public void mouseClicked(MouseEvent e) {} + public void mousePressed(MouseEvent e) {} + } } diff --git a/target/classes/BattleShip/AIGridGUI.class b/target/classes/BattleShip/AIGridGUI.class index 44a5878775297156ba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