|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectBattleshipState
public class BattleshipState
BattleshipState.java Created: Mon Mar 31 08:09:18 2003
Constructor Summary | |
---|---|
BattleshipState()
Creates a new BattleshipState instance with
size 10. |
|
BattleshipState(int size)
Creates a new BattleshipState instance with
given size. |
Method Summary | |
---|---|
int |
getSize()
getSize - return the size of the grid. |
boolean |
hasShip(int row,
int col)
hasShip - return whether or there is a ship
at the given row and column |
boolean |
isGuessed(int row,
int col)
isGuessed - return whether or not a given row
or column has been guessed |
boolean |
isWon()
isWon - returns whether or not all ship
segment positions have been guessed. |
boolean |
makeGuess(int row,
int col)
makeGuess - mark position as guessed and
return whether or not there is a ship segment at that
location. |
void |
placeShip(int rowMin,
int colMin,
int rowMax,
int colMax)
placeShip - place a ship at all positions in
the rectangle defined by the corners (rowMin, colMin) and
(rowMax, colMax) |
void |
setPlaying(boolean playing)
setPlaying - set whether or not the state is
in "playing" mode, affecting output of toString |
java.lang.String |
toString()
toString - return a String representation of the
current state grid. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BattleshipState()
BattleshipState
instance with
size 10.
public BattleshipState(int size)
BattleshipState
instance with
given size.
size
- an int
value - number of
rows/colsMethod Detail |
---|
public int getSize()
getSize
- return the size of the grid.
int
value - grid size = number of rows = number of columnspublic void placeShip(int rowMin, int colMin, int rowMax, int colMax)
placeShip
- place a ship at all positions in
the rectangle defined by the corners (rowMin, colMin) and
(rowMax, colMax)
rowMin
- an int
value - minimum rowcolMin
- an int
value - minimum columnrowMax
- an int
value - maximum rowcolMax
- an int
value - maximum columnpublic boolean makeGuess(int row, int col)
makeGuess
- mark position as guessed and
return whether or not there is a ship segment at that
location.
row
- an int
value - row of guesscol
- an int
value - column of guess
boolean
value - whether or not
guess is correctpublic boolean hasShip(int row, int col)
hasShip
- return whether or there is a ship
at the given row and column
row
- an int
value - row to checkcol
- an int
value - column to check
boolean
value - whether or not
there is a ship at the given row and columnpublic boolean isGuessed(int row, int col)
isGuessed
- return whether or not a given row
or column has been guessed
row
- an int
value - row to checkcol
- an int
value - column to check
boolean
value - whether or not a
given row and column has been guessedpublic boolean isWon()
isWon
- returns whether or not all ship
segment positions have been guessed.
boolean
value - whether or not all
ship segment positions have been guessed.public void setPlaying(boolean playing)
setPlaying
- set whether or not the state is
in "playing" mode, affecting output of toString
playing
- a boolean
value - whether or
not the state is in playing modepublic java.lang.String toString()
toString
- return a String representation of the
current state grid. A grid position with/without a ship is
denoted as '+'/'-'. If the state is in playing mode and the
position has not yet been guessed, the grid position is denoted
'?'.
toString
in class java.lang.Object
String
value
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |