Class Ships

java.lang.Object
  |
  +--PrintSuperClass
        |
        +--Board
              |
              +--Ships

public class Ships
extends Board

Used to create and maintain ships at sea. Extends Board Maintains a board with ships and current ship status


Defines Constant MAXSHIPS
Each Ship has Five Fields
String name, char code, int size,
boolean sunk, boolean placed

Note system has 6 boards per games Each player has public access to his defensive and offensive board Board with ships player is attacking is kept private

Player's makeMove with message IDPlaceShips will use a placeShips


Field Summary
static char[] code
          Character array each code represent unique ship identifier
static char DOWN
           
static java.lang.String[] exceptions
          Defines the Three exceptions thrown by placeShips method
static char LEFT
           
static int MAXSHIPS
          Global constants defines The number of Ships
static java.lang.String[] name
          String array representing the name of each ship
static char RIGHT
           
static int[] size
          int array representing the size of each ship
static char UP
          Four Codes for Ship Direction
 
Fields inherited from class Board
board, EMPTYCHAR, HITCHAR, MAXCOLS, MAXROWS, MISSCHAR
 
Constructor Summary
Ships()
          Ship constructor creates sunk and place array, constructor board is called first
 
Method Summary
 boolean allShipsPlaced()
          Used by battleship Simulator to verify correct placement of all ships
 boolean allShipsSunk()
          Used by battleship Simulator
 boolean checkSunk(Coordinates c)
          Used by BattleShip Simulator
 void clear()
          resets place and sunk arrays to false and clear board
 void copy(Ships s)
          Used by battleShip simulator to make a new copy of a ship object
 int findShip(char c)
           
 boolean placeShips(int id, Coordinates f, char direction)
           
 boolean placeShips(int id, Coordinates f, Coordinates s)
          Must be used by all Player's to place each ship individual
 void print(java.io.PrintWriter pw)
          Prints out current ship statistics index, code, name, placed and sunk and calls @see board#print
 void println(java.io.PrintWriter pw)
           
 void setSunk(int index)
          called by BattleShip simulator when the ship corresponding to to the specified index is sunk
 
Methods inherited from class Board
copy, get, get, main, set
 
Methods inherited from class PrintSuperClass
print, print, print, println, println, println
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXSHIPS

public static final int MAXSHIPS
Global constants defines The number of Ships

UP

public static final char UP
Four Codes for Ship Direction

DOWN

public static final char DOWN

LEFT

public static final char LEFT

RIGHT

public static final char RIGHT

name

public static final java.lang.String[] name
String array representing the name of each ship

code

public static final char[] code
Character array each code represent unique ship identifier

size

public static final int[] size
int array representing the size of each ship

exceptions

public static final java.lang.String[] exceptions
Defines the Three exceptions thrown by placeShips method
Constructor Detail

Ships

public Ships()
Ship constructor creates sunk and place array, constructor board is called first
Method Detail

setSunk

public void setSunk(int index)
called by BattleShip simulator when the ship corresponding to to the specified index is sunk

copy

public void copy(Ships s)
Used by battleShip simulator to make a new copy of a ship object

clear

public void clear()
resets place and sunk arrays to false and clear board
Overrides:
clear in class Board

allShipsSunk

public boolean allShipsSunk()
Used by battleship Simulator
Returns:
true if all ships have been sunk

allShipsPlaced

public boolean allShipsPlaced()
Used by battleship Simulator to verify correct placement of all ships
Returns:
true if all ships have been placed on Board

findShip

public int findShip(char c)
Parameters:
c - is the character code that uniquely identifies the ship
Returns:
Index of ship relative to argument 'char c'

checkSunk

public boolean checkSunk(Coordinates c)
Used by BattleShip Simulator
Parameters:
c - is Coordinates representing location containing a hit ship

print

public void print(java.io.PrintWriter pw)
Prints out current ship statistics index, code, name, placed and sunk and calls @see board#print
Overrides:
print in class Board

println

public void println(java.io.PrintWriter pw)
Overrides:
println in class Board

placeShips

public boolean placeShips(int id,
                          Coordinates f,
                          char direction)
                   throws java.lang.Exception
Parameters:
id - is Ship id to be places
f - is front coordinate of ship
direction, - is direction of ship placement, UP, DOWN, LEFT, RIGHT

placeShips

public boolean placeShips(int id,
                          Coordinates f,
                          Coordinates s)
                   throws java.lang.Exception
Must be used by all Player's to place each ship individual
Parameters:
id - represent the ship index ID
f - represents the starting front coordinate of the ship
s - represents the stern rear coordinate of ship
Returns:
true if ship placed successfully
Throws:
with - messages NoSuchShip, shipExists, OutOfBounds,