From 186ea8c1f2ecfd06d8e0b237e5b7204557d664ac Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:14:12 +0100 Subject: [PATCH] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index 783cc30..f682b1c 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -361,6 +361,19 @@ public class AIGridGUI extends JPanel { cellsHit[guessLocation] = true; } } + + //Mark game as not over unless all ships killed. + for(Ship sh : allShips) { + if(!sh.isKilled()) { + gameOver = false; + } + } + + //Game over message. + if(gameOver) { + text = "You Lost in " + numOfGuesses + " guesses."; + endGame = true; + } } //Return the location of a cell one space in the given direction, or return -1 if out of bounds.