From a7ef8c818e2c6d4bbfd34e90d5ec17d96c6de1fd Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:09:36 +0100 Subject: [PATCH] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 042c5ba..783cc30 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -349,6 +349,16 @@ public class AIGridGUI extends JPanel { if(!unkilledCells) { randomGuess = true; } + } else { + //If cell hit but not killed, mark cell appropriately. + text = "Other player got a hit. Your turn."; + b.setBackground(Color.red); + //If previously random guessing, switch to locking onto the hit cell. + if(randomGuess) { + f = b.getGridLocation(); + randomGuess = false; + } + cellsHit[guessLocation] = true; } } }