|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectGrid
public class Grid
This class models a game board. It is multi-purpose, in that the same object can present different "views" -- one to the player who has placed the ships, and one to her opponent, who only sees the results of strikes. Note that some of the methods in this class will need to update save-game state -- in particular, place() and registerStrike().
| Constructor Summary | |
|---|---|
Grid()
|
|
| Method Summary | |
|---|---|
boolean |
canPlace(Ship s)
Returns true if the given Ship can be legally placed on the board, false otherwise. |
java.lang.String |
explainIllegalPlacement(Ship s)
Returns a textual explanation for why a given Ship cannot legally be placed on the board. |
Ship |
getLastStruck()
Returns a reference to the Ship hit by the last strike, or null if the last strike missed all ships. |
Ship[] |
getLiveShips()
Returns a newly-allocated array of references to the ships on this grid that have not yet been destroyed. |
int |
getNumRows()
Returns the number of rows in this Grid. |
Ship[] |
getSunkenShips()
Returns a newly-allocated array of references to the ships on this grid that have been destroyed. |
void |
place(Ship s)
Places a given Ship on the board. |
boolean |
registerStrike(BoardPoint strike)
Registers a strike on this grid. |
void |
setPlayerView()
Sets this Grid to "player view mode." In player view mode, the positions of ships and the results of strikes are shown. |
void |
setResultsView()
Sets this Grid to "results view mode." In results view mode, only the results of strikes are shown. |
java.lang.String |
stringForRow(int row)
Returns a textual representation of the given row. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Grid()
| Method Detail |
|---|
public boolean canPlace(Ship s)
s - a Ship.
public java.lang.String explainIllegalPlacement(Ship s)
s - a Ship
public void place(Ship s)
s - a Ship.public Ship[] getLiveShips()
public Ship[] getSunkenShips()
public boolean registerStrike(BoardPoint strike)
strike - a BoardPoint
public Ship getLastStruck()
public void setPlayerView()
public void setResultsView()
public java.lang.String stringForRow(int row)
row - the row to convert to a String
public int getNumRows()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||