Class Game

java.lang.Object
battleship.model.game.Game

public class Game extends Object
  • Constructor Details

    • Game

      public Game(int sizeHorizontal, int sizeVertical) throws IllegalArgumentException
      Create new game.
      Parameters:
      sizeHorizontal - horizontal size of the ocean
      sizeVertical - vertical size of the ocean
      Throws:
      IllegalArgumentException - cannot create ocean with this parameters
  • Method Details

    • setGameMode

      public void setGameMode(EnumSet<GameMode> mode, int torpedoCounter) throws IllegalArgumentException
      Set the game mode.
      Parameters:
      mode - enum set of options
      torpedoCounter - torpedo counter
      Throws:
      IllegalArgumentException - when torpedo counter mismatching with game mode
    • recognizeMode

      public static EnumSet<GameMode> recognizeMode(int torpedoCounter, boolean recoveryMode)
      Parameters:
      torpedoCounter - number of available torpedo
      recoveryMode - recovery mode turned on/off
      Returns:
      Game mode
    • placeShipsOnOcean

      public void placeShipsOnOcean(int[] counters) throws RuntimeException
      Placing ship on the Ocean.
      Parameters:
      counters - array of numbers, where these numbers are listed in the order which corresponds to ship types sizes
      Throws:
      RuntimeException - if ocean size is too small for the input specified fleet
    • addListener

      public void addListener(StatusChangedListener user)
      (Only for recovery mode) Subscribes listener to user status changed event.
      Parameters:
      user - user to subscribe.
    • hitOnPlace

      public AttackReport hitOnPlace(Point point, FiringMode firingMode) throws IllegalArgumentException
      Attack on specified point on ocean.
      Parameters:
      point - point to attack
      firingMode - general / torpedo
      Returns:
      attack report
      Throws:
      IllegalArgumentException - if firing mode = torpedo and there is no available torpedo
    • restorePreviousHealthFleet

      public void restorePreviousHealthFleet(int healthScoresToAdd)
      Restore fleet health. (only for ship recovery mode).
      Parameters:
      healthScoresToAdd - health scores to add
    • updatePointsToRecover

      public void updatePointsToRecover(List<Point> points)
      Update list of points to recover (only for ship recovery mode).
      Parameters:
      points - list of points
    • getPointsToRecover

      public List<Point> getPointsToRecover()
      (only for ship recovery mode)
      Returns:
      list of points to recover
    • clearPointsToRecover

      public void clearPointsToRecover()
      (only for ship recovery mode) Clear list.