diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index db4a1a2..1ba45bf 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -445,6 +445,25 @@ 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(); + if(e.getButton() == MouseEvent.BUTTON1 && clear) { + highlightCells(cell, 1); + if(allShips.indexOf(shipToPlace) < (allShips.size() - 1)) { + //If more ships still to place, switch to next ship to be placed. + int nextShip = allShips.indexOf(shipToPlace) + 1; + shipToPlace = allShips.get(nextShip); + text = "Place " + shipToPlace.getName() + ". Right click to toggle horizontal/vertical."; + } else { + //If no more ships to place, disable cells and start gameplay. + for(int i = 0; i < buttons.size(); i++) { + BSButton bsb = buttons.get(i); + bsb.removeMouseListener(listeners.get(i)); + bsb.setEnabled(false); + } + text = "Ready to start the game."; + shipsPlaced = true; + } + clear = false; + } } public void mouseExited(MouseEvent e) {