|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object Board
public class Board
Represents the board .
Field Summary | |
---|---|
static int |
MISSED
A state to represent one of several possible states for a Cell object |
static int |
NOT_SHOT_AT
A state to represent one of several possible states for a Cell object |
static int |
SAME_TARGET
A state to represent one of several possible states for a Cell object |
static int |
SHIP_HIT
A state to represent one of several possible states for a Cell object |
static int |
SHIP_SUNK
A state to represent one of several possible states for a Cell object |
Constructor Summary | |
---|---|
Board(int x,
int y)
This constructor for the Board object should initialize the board, setting its x and y dimensions to the given values and initializing the cells and shiplist to their initial states. |
Method Summary | |
---|---|
boolean |
allShipsSunk()
This method returns true if all ships on the board have been sunk, and it returns false otherwise. |
void |
clearBoard()
This method intializes the cell array and ship list references. |
void |
generateRandomBoard(int numberOfShips)
This method resets the board to a new state containing the number of ships given by the numberOfShips parameter. |
Cell |
getCellAt(int x,
int y)
Given the x and y coordinates of a cell in the board, this method returns a reference to the cell at that position (x,y). |
Ship |
getShip(int index)
Given an integer index to a ship in the ship list, this method returns the ship at the requested index. |
int |
getShipNumber(Ship ship)
Given a reference to a ship in the ship list, this method returns the integer index of the given ship in the list. |
boolean |
isValidBoard()
This method returns true if the board configuration is valid, and it returns false otherwise. |
void |
placeShip(Ship aShip)
This method places the given ship (aShip) on the board by marking each cell that the ship occupies (with a call to setShipOnCell) and then by adding the ship to the shipList. |
void |
placeShips(ShipList ships)
This method takes a ShipList object as a parameter. |
void |
printShipList()
Prints the ship list by calling the print method of the ship list. |
int |
processShot(int x,
int y)
This method processes a shot fired at cell x,y. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int NOT_SHOT_AT
public static final int MISSED
public static final int SAME_TARGET
public static final int SHIP_HIT
public static final int SHIP_SUNK
Constructor Detail |
---|
public Board(int x, int y)
x
- the x-coordinate.y
- the y-coordinate.Method Detail |
---|
public void clearBoard()
public int getShipNumber(Ship ship)
ship
- the instance to be searched.
public Ship getShip(int index)
index
- the index requested.
public Cell getCellAt(int x, int y)
x
- the x-coordinate.y
- the y-coordinate.
public void placeShips(ShipList ships)
ships
- the list of ships.public boolean allShipsSunk()
public boolean isValidBoard()
public void generateRandomBoard(int numberOfShips)
numberOfShips
- number of Ships.public void placeShip(Ship aShip)
aShip
- the instance of ship to be placedpublic int processShot(int x, int y)
x
- the x coordinate of the target.y
- the y coordinate of the target.public void printShipList()
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |