Class Battleship

java.lang.Object
  extended byBattleship

public class Battleship
extends Object

Details of the current game


Field Summary
private  ShipBoard comp
          Computer's ship board
private  GuessBoard user
          User's guess board
private  boolean win
          Status of the game : true when user has won
 
Constructor Summary
(package private) Battleship()
          Initialize the game.
 
Method Summary
 int[] compStat()
           
 int guessStatus(Location l)
          Get the results of user's guess.
 int numUserGuess()
           
 int userGuess(Location l)
          Carry out the user's guess, by modifying the shipBoard and guessBoard
 boolean win()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

comp

private ShipBoard comp
Computer's ship board


user

private GuessBoard user
User's guess board


win

private boolean win
Status of the game : true when user has won

Constructor Detail

Battleship

Battleship()
Initialize the game. Places computer's ships randomly on the board.

Method Detail

guessStatus

public int guessStatus(Location l)
Get the results of user's guess.

Parameters:
l - Location to be queried
Returns:
1 if location l has not been guessed; 2 if location l was a hit; 3 if location l was a miss

userGuess

public int userGuess(Location l)
Carry out the user's guess, by modifying the shipBoard and guessBoard

Parameters:
l - Location that the user guesses
Returns:
index of the ship (in computer's shipBoard) that is hit. Returns 5 if no ship is hit.

compStat

public int[] compStat()
Returns:
An array containing the status (number of holes hit) of computer's ships

numUserGuess

public int numUserGuess()
Returns:
The number of guesses made by user

win

public boolean win()
Returns:
True if user has finished the game