Class PlacementUI

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

public class PlacementUI extends JFrame implements PlacementHandler
Graphical interface for the ship placement phase. Provides a grid for players to position their fleet and controls to select ship types and orientation.
Author:
Alessio Cascini
See Also:
  • Field Details

    • gridSize

      public static final int gridSize
      The size of the game board (10x10)
      See Also:
    • shipInfos

      public static final ShipInfo[] shipInfos
      Predefined fleet configuration with ship names and their respective sizes
  • Constructor Details

    • PlacementUI

      public PlacementUI()
      Initializes the placement window, sets up the grid of buttons, and configures the control panel.
  • Method Details

    • main

      public static void main(String[] args)
      Main entry point for the client application.
      Parameters:
      args - Command line arguments
    • getSelectedShipIndex

      public int getSelectedShipIndex()
      Description copied from interface: PlacementHandler
      Retrieves the index of the currently selected ship from the UI.
      Specified by:
      getSelectedShipIndex in interface PlacementHandler
      Returns:
      The index of the selected ship in the fleet list
    • getSelectedOrientationIndex

      public int getSelectedOrientationIndex()
      Description copied from interface: PlacementHandler
      Retrieves the selected orientation (e.g., Horizontal or Vertical).
      Specified by:
      getSelectedOrientationIndex in interface PlacementHandler
      Returns:
      The index representing the chosen orientation
    • showMessage

      public void showMessage(String message)
      Description copied from interface: PlacementHandler
      Displays a feedback message to the user, such as errors or instructions.
      Specified by:
      showMessage in interface PlacementHandler
      Parameters:
      message - The string content to be displayed
    • highlightShipCells

      public void highlightShipCells(Ship ship)
      Colors the cells occupied by a newly placed ship to provide visual feedback.
      Specified by:
      highlightShipCells in interface PlacementHandler
      Parameters:
      ship - The ship object containing the coordinates to highlight
    • proceedToGameUI

      public void proceedToGameUI(boolean isFirstPlayer)
      Closes the placement screen and opens the main game interface.
      Specified by:
      proceedToGameUI in interface PlacementHandler
      Parameters:
      isFirstPlayer - Boolean indicating if this client is Player 1