Package student.micro.battleship
Enum CellStatus
- All Implemented Interfaces:
Serializable
,Comparable<CellStatus>
,java.lang.constant.Constable
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 ConstantsEnum ConstantDescriptionRepresents 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 TypeMethodDescriptionReturn 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
firedOn()
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[]
values()
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
-
Enum Constant Details
-
EMPTY
Represents an empty cell that has not been fired on. -
SHIP
Represents a cell that is occupied by (part of) a ship. -
MISS
Represents an empty cell that has been fired on (a miss). -
HIT
Represents a cell that has been fired on and that is occupied by (part of) a ship (a hit).
-
-
Method Details
-
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
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 nameNullPointerException
- 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
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
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.
-