Browse Source

update

main
fdai4581 2 years ago
parent
commit
399b0c82f1
  1. 25
      src/main/java/BattleShip/GridGUI.java

25
src/main/java/BattleShip/GridGUI.java

@ -14,6 +14,7 @@ public class GridGUI {
ArrayList<Ship> allShips = new ArrayList<Ship>();
int[] testLocations;
int numOfGuesses = 0;
String text = "";
int rows;
int columns;
boolean clicked = false;
@ -80,6 +81,30 @@ public class GridGUI {
boolean killed = false;
numOfGuesses++;
boolean gameOver = true;
cell.setEnabled(false);
cell.setBorder(loweredBevel);
if(s == null) {
//Mark cell as missed.
text = "You missed. Other player's turn...";
cell.setBackground(Color.lightGray);
} else {
killed = s.counter();
if(killed) {
//Mark all of the ship's cells as killed.
text = "You sunk the " + s.getName() + "! Other player's turn...";
for(BSButton bu : buttons) {
if(bu.getCellContents() == s) {
bu.setBackground(darkRed);
}
}
} else {
//Mark cell as hit.
text = "You got a hit. Other player's turn...";
cell.setBackground(Color.red);
}
}
}
}
}
Loading…
Cancel
Save