Browse Source

Update Implementation AIGridGUI class

main
Thoumi Ngonga Brice 2 years ago
parent
commit
350462421e
  1. 29
      src/main/java/BattleShip/AIGridGUI.java
  2. BIN
      target/classes/BattleShip/AIGridGUI.class

29
src/main/java/BattleShip/AIGridGUI.java

@ -26,7 +26,10 @@ public class AIGridGUI extends JPanel {
int f; // it is the first int f; // it is the first
Color Red = new Color(100, 0, 0); // Color Red = new Color(100, 0, 0); //
Border loweredBevel = BorderFactory.createLoweredBevelBorder(); Border loweredBevel = BorderFactory.createLoweredBevelBorder();
Border raisedbevel = BorderFactory.createRaisedBevelBorder();
Border defaultBorder; Border defaultBorder;
//empty = BorderFactory.createEmptyBorder(4, 4, 4, 4);
Border compound = BorderFactory.createCompoundBorder();
Ship shipToPlace; Ship shipToPlace;
boolean vertical = false; boolean vertical = false;
boolean clear; boolean clear;
@ -499,7 +502,7 @@ public class AIGridGUI extends JPanel {
public void highlightCells(BSButton b, int x) { public void highlightCells(BSButton b, int x) {
BSButton cell = b; BSButton cell = b;
int actionToTake = x;
int action = x;
clear = true; clear = true;
//Check whether sufficient spaces are clear to place the ship. //Check whether sufficient spaces are clear to place the ship.
@ -511,5 +514,29 @@ public class AIGridGUI extends JPanel {
} }
} }
} }
if(clear) {
if(vertical) {
for(int i = 0; i < shipToPlace.getLength(); i++) {
BSButton bsb = buttons.get(cell.getGridLocation() + (i * columns));
//If mouse entered, highlight cells via lowered bevel.
if(action == 1) {
bsb.setBorder(raisedbevel);
} else {
//If mouse released, place ship and color ship cells.
if(action == 2) {
bsb.setCellContents(shipToPlace);
bsb.setBackground(Color.gray);
bsb.setBorder(raisedbevel);
} else {
//If mouse exited, unhighlight cells.
bsb.setBorder(compound);
}
}
}
}
}
} }
} }

BIN
target/classes/BattleShip/AIGridGUI.class

Loading…
Cancel
Save