From cbdc91630f2aa6a0670ec1fdfd43de61cb0dcd45 Mon Sep 17 00:00:00 2001 From: Thoumi Ngonga Brice Date: Tue, 7 Feb 2023 01:02:04 +0100 Subject: [PATCH] Update Implementation AIGridGUI class --- src/main/java/BattleShip/AIGridGUI.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/BattleShip/AIGridGUI.java b/src/main/java/BattleShip/AIGridGUI.java index d802f03..57aaab0 100644 --- a/src/main/java/BattleShip/AIGridGUI.java +++ b/src/main/java/BattleShip/AIGridGUI.java @@ -315,6 +315,26 @@ public class AIGridGUI extends JPanel { } } + + //Mark the guess on the grid. + + cellsGuessed[guessLocation] = true; + b = buttons.get(guessLocation); + s = b.getCellContents(); + b.setBorder(loweredBevel); + + if(s == null) { + //If no ship in that cell, mark as a miss. + text = "Other player missed. Your turn."; + b.setBackground(Color.BLUE); + } else { + //Check if guess killed a ship. + killed = s.counter(); + if(killed) { + text = "Your " + s.getName() + " was sunk. Your turn."; + boolean unkilledCells = false; + } + } } //Return the location of a cell one space in the given direction, or return -1 if out of bounds.