Enum CellStatus

java.lang.Object
java.lang.Enum<CellStatus>
student.micro.battleship.CellStatus
All Implemented Interfaces:
Serializable, Comparable<CellStatus>, java.lang.constant.Constable

public enum CellStatus extends Enum<CellStatus>
Represents a move that sets the positions of all the player's ships on his or her board in the game "Battleship". Each player makes one of these moves at the start of the game to position their ships. In "devious" variations of Battleship, players may get an opportunity to make these moves later to "reposition" their ships, within limits.
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Represents an empty cell that has not been fired on.
    Represents a cell that has been fired on and that is occupied by (part of) a ship (a hit).
    Represents an empty cell that has been fired on (a miss).
    Represents a cell that is occupied by (part of) a ship.
  • Method Summary

    Modifier and Type
    Method
    Description
    Return the new cell status that would be obtained by firing on a cell of this cell status (e.g., EMPTY returns MISS and SHIP returns HIT).
    boolean
    Determine if this cell status indicates that the cell is occupied by a ship.
    boolean
    Determine if this cell status indicates that the cell has been fired upon by the opponent.
    Return the new cell status that would be obtained by firing on a cell of this cell status (e.g., EMPTY returns MISS and SHIP returns HIT).
    static CellStatus
    Returns the enum constant of this type with the specified name.
    static CellStatus[]
    Returns an array containing the constants of this enum type, in the order they are declared.

    Methods inherited from class java.lang.Enum

    compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • EMPTY

      public static final CellStatus EMPTY
      Represents an empty cell that has not been fired on.
    • SHIP

      public static final CellStatus SHIP
      Represents a cell that is occupied by (part of) a ship.
    • MISS

      public static final CellStatus MISS
      Represents an empty cell that has been fired on (a miss).
    • HIT

      public static final CellStatus HIT
      Represents a cell that has been fired on and that is occupied by (part of) a ship (a hit).
  • Method Details

    • values

      public static CellStatus[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static CellStatus valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • firedOn

      public boolean firedOn()
      Determine if this cell status indicates that the cell has been fired upon by the opponent.
      Returns:
      True if this cell has been fired on (MISS or HIT), or false if it has not (EMPTY or SHIP).
    • containsShip

      public boolean containsShip()
      Determine if this cell status indicates that the cell is occupied by a ship.
      Returns:
      True if a ship occupies this cell (SHIP or HIT), or false otherwise (EMPTY or MISS).
    • afterFiring

      public CellStatus afterFiring()
      Return the new cell status that would be obtained by firing on a cell of this cell status (e.g., EMPTY returns MISS and SHIP returns HIT).
      Returns:
      The new cell status that a cell should change to if it is fired on.
    • hideShips

      public CellStatus hideShips()
      Return the new cell status that would be obtained by firing on a cell of this cell status (e.g., EMPTY returns MISS and SHIP returns HIT).
      Returns:
      The new cell status that a cell should change to if it is fired on.