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 44a5878..5cba194 100644 Binary files a/target/classes/BattleShip/AIGridGUI.class and b/target/classes/BattleShip/AIGridGUI.class differ