Class GuessBoard

java.lang.Object
  extended byGuessBoard

public class GuessBoard
extends Object

Records all the guesses and their results of a player


Field Summary
private  Location[] guess
          An array holding all locations guessed so far
private  int numGuess
          Number of guesses so far
private  boolean[] result
          Results of all guesses so far.
 
Constructor Summary
(package private) GuessBoard()
          Initializes the arrays to the maximum size (100)
 
Method Summary
 boolean isNew(Location l)
           
 void markGuess(Location l, boolean res)
          Marks the result of a guess
 int numGuesses()
           
 boolean wasHit(Location l)
          Tests whether a location was guessed and hit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

guess

private Location[] guess
An array holding all locations guessed so far


result

private boolean[] result
Results of all guesses so far. result[i] is true if the guess at location guess[i] hit a ship.


numGuess

private int numGuess
Number of guesses so far

Constructor Detail

GuessBoard

GuessBoard()
Initializes the arrays to the maximum size (100)

Method Detail

isNew

public boolean isNew(Location l)
Parameters:
l - Location to be checked
Returns:
True if location l has already been guessed.

markGuess

public void markGuess(Location l,
                      boolean res)
Marks the result of a guess

Parameters:
l - Location corresponding to the guess
res - Result of the guess at location l (true=hit, false=miss)

wasHit

public boolean wasHit(Location l)
Tests whether a location was guessed and hit

Parameters:
l - Location to test
Returns:
True if location l was guessed earlier and was a hit

numGuesses

public int numGuesses()
Returns:
The number of guesses so far