Browse Source

Update Implementation AIGridGUI class

main
Thoumi Ngonga Brice 2 years ago
parent
commit
cd138ac897
  1. 13
      src/main/java/BattleShip/AIGridGUI.java

13
src/main/java/BattleShip/AIGridGUI.java

@ -443,7 +443,8 @@ public class AIGridGUI extends JPanel {
} }
public void mouseReleased(MouseEvent e) { 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) { public void mouseExited(MouseEvent e) {
@ -457,5 +458,15 @@ public class AIGridGUI extends JPanel {
BSButton cell = b; BSButton cell = b;
int actionToTake = x; int actionToTake = x;
clear = true; 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;
}
}
}
} }
} }
Loading…
Cancel
Save