Class ShipBoard

java.lang.Object
  extended byShipBoard

public class ShipBoard
extends Object

Records all the ships of a player


Field Summary
private  Ship[] fleet
          All the ships on this ship board
private  int size
          The number of ships on this ship board
 
Constructor Summary
(package private) ShipBoard()
          Builds a standard ship board containing five ships in the order : PatrolBoat,Destroyer,Submarine,BattleShip,Carrier.
(package private) ShipBoard(Ship[] f, int s)
          Builds a Shipboard containing specified ships
 
Method Summary
 int[] getFleetStat()
          Get the status of all ships on this Shipboard
 boolean hitShip(Location l, int n)
          Check if the specified ship is hit in a location
 boolean isDestroyed()
          Test if all ships on this Shipboard are sunk
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

size

private int size
The number of ships on this ship board


fleet

private Ship[] fleet
All the ships on this ship board

Constructor Detail

ShipBoard

ShipBoard(Ship[] f,
          int s)
Builds a Shipboard containing specified ships

Parameters:
f - the ships to be added to this Shipboard
s - the number of ships to be added

ShipBoard

ShipBoard()
Builds a standard ship board containing five ships in the order : PatrolBoat,Destroyer,Submarine,BattleShip,Carrier. Places all the ships randomly on the board.

Method Detail

hitShip

public boolean hitShip(Location l,
                       int n)
Check if the specified ship is hit in a location

Parameters:
l - Location to check
n - index of the ship to check
Returns:
true if ship fleet[n] occupies location l

isDestroyed

public boolean isDestroyed()
Test if all ships on this Shipboard are sunk

Returns:
true if all ships are sunk

getFleetStat

public int[] getFleetStat()
Get the status of all ships on this Shipboard

Returns:
An array of length size. The entry in the i-th position is the number of hits on ship fleet[i]