Class GameUI

All Implemented Interfaces:
GameActionHandler, ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class GameUI extends JFrame implements GameActionHandler
The main gameplay interface. Displays two grids: the opponent's grid (interactive for attacking) and the player's grid (read-only, showing own ships and opponent's hits).
Author:
Alessio Cascini
See Also:
  • Constructor Details

    • GameUI

      public GameUI(List<Ship> shipPositions, boolean isFirstPlayer)
      Constructs the game interface, initializes the grids, and renders the player's ships.
      Parameters:
      shipPositions - The list of ships placed by the player in the previous phase
      isFirstPlayer - Boolean flag indicating if this client starts the game
  • Method Details

    • showMessage

      public void showMessage(String message)
      Description copied from interface: GameActionHandler
      Displays a game-related message to the player, such as turn notifications or win/loss alerts.
      Specified by:
      showMessage in interface GameActionHandler
      Parameters:
      message - The text content to be shown in the UI
    • processMove

      public void processMove(boolean isPlayerMove, int row, int col, int[][] result)
      Updates the UI based on the result of a move. Logic: - 0 elements: Miss (Blue) - 1 element: Hit (Red) - >1 elements: Ship Sunk (Black) - Sentinel [-1, -1]: Game Over
      Specified by:
      processMove in interface GameActionHandler
      Parameters:
      isPlayerMove - True if the move was made by this client, false if by opponent
      row - The row of the move
      col - The column of the move
      result - Data from the server indicating the outcome