Interface Ship

All Known Implementing Classes:
AircraftCarrier, Barge, Cruiser, Destroyer

public interface Ship

Ship is an interface that all of your ship classes must implement.

Author:
willb

Field Summary
static int EAST
           
static int NORTH
           
static int SOUTH
           
static int WEST
           
 
Method Summary
 char getCharForPoint(BoardPoint strike)
           Returns the character to display for a given BoardPoint.
 BoardPoint[] getExtent()
           Returns a newly-allocated array of BoardPoints, one for each BoardPoint this Ship occupies.
 int getFacing()
           Returns the direction this Ship is facing.
 java.lang.String getName()
           Returns a human-readable name for this Ship, such as "aircraft carrier."
 BoardPoint getOrigin()
          Returns the origin point for this Ship.
 boolean isDestroyed()
           Returns true if this Ship is destroyed, false otherwise.
 boolean occupies(BoardPoint strike)
           Returns true if this Ship occupies the given space, false otherwise.
 void registerStrike(BoardPoint strike)
           Registers the result of a strike at the given point; records the strike and possibly destroys the ship.
 void setFacing(int facing)
           Sets the direction this ship is facing.
 void setOrigin(BoardPoint origin)
           Sets the origin of this ship as a BoardPoint.
 

Field Detail

NORTH

static final int NORTH
See Also:
Constant Field Values

EAST

static final int EAST
See Also:
Constant Field Values

SOUTH

static final int SOUTH
See Also:
Constant Field Values

WEST

static final int WEST
See Also:
Constant Field Values
Method Detail

isDestroyed

boolean isDestroyed()
Returns true if this Ship is destroyed, false otherwise.

Returns:
true if this Ship is destroyed, false otherwise.

getName

java.lang.String getName()
Returns a human-readable name for this Ship, such as "aircraft carrier."

Returns:
a human-readable name for this Ship, such as "aircraft carrier."

occupies

boolean occupies(BoardPoint strike)
Returns true if this Ship occupies the given space, false otherwise.

Parameters:
strike - a BoardSpace that this Ship may or may not occupy
Returns:
true if this Ship occupies the given space, false otherwise.

registerStrike

void registerStrike(BoardPoint strike)
Registers the result of a strike at the given point; records the strike and possibly destroys the ship.

Parameters:
strike - a BoardSpace

getOrigin

BoardPoint getOrigin()
Returns the origin point for this Ship.

Returns:
the origin point for this Ship.

getFacing

int getFacing()
Returns the direction this Ship is facing.

Returns:
the direction this Ship is facing.

getExtent

BoardPoint[] getExtent()
Returns a newly-allocated array of BoardPoints, one for each BoardPoint this Ship occupies.

Returns:
an array of BoardPoints, as above.

getCharForPoint

char getCharForPoint(BoardPoint strike)
Returns the character to display for a given BoardPoint. This is one of the following:
  1. (char)0, if this Ship does not occupy the given BoardPoint
  2. 'X', if this Ship has been struck at the given BoardPoint
  3. or a ship-dependent character (e.g. 'A' for aircraft carriers) if this Ship occupies the given point but has not been hit.

Parameters:
strike -
Returns:
a character, as above.

setOrigin

void setOrigin(BoardPoint origin)
Sets the origin of this ship as a BoardPoint.

Parameters:
origin -

setFacing

void setFacing(int facing)
Sets the direction this ship is facing. Precondition: facing is one of Ship.NORTH, Ship.EAST, Ship.SOUTH, Ship.WEST.

Parameters:
facing - the direction this ship is facing.