|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMineSweeperBoardBase
A MineSweeperBoard holds a representation of the contents of the playing field for a Mine Sweeper game. The playing field is represented using a 2 dimensional array of integer values. The integer value stored in each cell of the array indicates the icon which will appear in the cooresponding cell of the graphical user interface for the game.
This abstract base class defines the basic features of a MineSweeperBoard, which you must create.
Field Summary | |
static int |
COVERED_CELL
A constant value representing a covered cell. |
static int |
FLAG
A constant value representing a cell which does not contain a mine but has had a flag placed on it. |
static int |
FLAGGED_MINE
A constant value representing a cell which contains a mine and has had a flag placed on it. |
static int |
INVALID_CELL
A constant value representing the contents of an invalid cell. |
static int |
MINE
A constant value representing a a cell that has not been uncovered yet but contains a mine. |
static int |
UNCOVERED_MINE
A constant value representing a cell containing a mine that has been uncovered. |
Constructor Summary | |
MineSweeperBoardBase()
|
Method Summary | |
protected void |
clearBoard()
Cover all cells in the board. |
boolean |
equals(Object other)
Check whether two boards have the same cell contents. |
abstract void |
flagCell(int row,
int col)
Place or remove a flag from the specified cell. |
abstract boolean |
gameLost()
Determine if the player has lost the current game. |
abstract boolean |
gameWon()
Determine if the player has won the current game. |
abstract int |
getCell(int row,
int col)
Get the contents of the specified cell on this MineSweeperBoard. |
abstract int |
getColumns()
Get the number of columns in this MineSweeperBoard. |
abstract int |
getRows()
Get the number of rows in this MineSweeperBoard. |
void |
loadBoardState(String[] rows)
Reset the board using a given array of strings. |
abstract int |
numAdjMines(int row,
int col)
Count the number of mines that appear in cells that are adjacent to the specified cell. |
protected void |
placeMines(int numMines)
Place a specified number of mines at random locations on this board. |
void |
printBoard(PrintWriter out)
Print the contents of this MineSweeperBoard to the specified output stream. |
abstract void |
revealBoard()
Uncover all of the cells on the board. |
protected abstract void |
setCell(int row,
int col,
int value)
Set the contents of the specified cell on this MineSweeperBoard. |
abstract void |
uncoverCell(int row,
int col)
Uncover the specified cell. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int COVERED_CELL
public static final int FLAG
public static final int FLAGGED_MINE
public static final int INVALID_CELL
public static final int MINE
public static final int UNCOVERED_MINE
Constructor Detail |
public MineSweeperBoardBase()
Method Detail |
protected void clearBoard()
public boolean equals(Object other)
other
- the other object to compare withpublic abstract void flagCell(int row, int col)
row
- the row of the cell to be flagged/unflaggedcol
- the column of the cell to be flagged/unflaggedpublic abstract boolean gameLost()
public abstract boolean gameWon()
public abstract int getCell(int row, int col)
row
- the row containing the cell.col
- the column containing the cell.
public abstract int getColumns()
public abstract int getRows()
public void loadBoardState(String[] rows)
rows
- the array of strings to interpret; the array length must
be the same as the number of rows in this board, and
each string's length must be the same as the number of
columns in this board.public abstract int numAdjMines(int row, int col)
row
- the row of the cell.col
- the column of the cell.
protected void placeMines(int numMines)
numMines
- the number of mines to placepublic void printBoard(PrintWriter out)
O = covered cell F = flag M = flagged mine + = covered mine * = uncovered mine (about to explode!) 1..9 or space = uncovered cell
out
- the output stream to print the board description onpublic abstract void revealBoard()
protected abstract void setCell(int row, int col, int value)
row
- the row containing the cellcol
- the column containing the cell
public abstract void uncoverCell(int row, int col)
row
- the row of the cell to be uncovered.col
- the column of the cell to be uncovered.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |