Browse Source

Update Implementation AIGridGUI class

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

16
src/main/java/BattleShip/AIGridGUI.java

@ -333,6 +333,22 @@ public class AIGridGUI extends JPanel {
if(killed) { if(killed) {
text = "Your " + s.getName() + " was sunk. Your turn."; text = "Your " + s.getName() + " was sunk. Your turn.";
boolean unkilledCells = false; boolean unkilledCells = false;
for(BSButton bu : buttons) {
//Mark killed cells.
if(bu.getCellContents() == s) {
bu.setBackground(Red);
cellsKilled[bu.getGridLocation()] = true;
}
//Mark if any cell remains that has been hit but not yet killed. If so, lock onto that cell.
if(cellsHit[bu.getGridLocation()] && !cellsKilled[bu.getGridLocation()]) {
f = bu.getGridLocation();
unkilledCells = true;
}
}
//If all hit cells have been killed, return to random guessing.
if(!unkilledCells) {
randomGuess = true;
}
} }
} }
} }

Loading…
Cancel
Save