|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectMineSweeperBoardBase
MineSweeperBoard
A MineSweeperBoard holds a representation of the contents of the playing field for a Mine Sweeper game. The playing field is represented using a two-dimensional array of integer values. The integer value stored in each cell of the array indicates the icon which will appear in the corresponding cell of the graphical user interface for the game. Your job is to implement all the methods in this class skeleton and write a set of test cases for this class.
Field Summary |
Fields inherited from class MineSweeperBoardBase |
COVERED_CELL, FLAG, FLAGGED_MINE, INVALID_CELL, MINE, UNCOVERED_MINE |
Constructor Summary | |
MineSweeperBoard(int rows,
int cols,
int numMines)
Construct a new MineSweeperBoard with the given dimensions. |
Method Summary | |
void |
flagCell(int row,
int col)
Place or remove a flag from the specified cell. |
boolean |
gameLost()
Determine if the player has lost the current game. |
boolean |
gameWon()
Determine if the player has won the current game. |
int |
getCell(int row,
int col)
Get the contents of the specified cell on this MineSweeperBoard. |
int |
getColumns()
Get the number of columns in this MineSweeperBoard. |
int |
getRows()
Get the number of rows in this MineSweeperBoard. |
int |
numAdjMines(int row,
int col)
Count the number of mines that appear in cells that are adjacent to the specified cell. |
void |
revealBoard()
Uncover all of the cells on the board. |
protected void |
setCell(int row,
int col,
int value)
Set the contents of the specified cell on this MineSweeperBoard. |
void |
uncoverCell(int row,
int col)
Uncover the specified cell. |
Methods inherited from class MineSweeperBoardBase |
clearBoard, equals, loadBoardState, placeMines, printBoard |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public MineSweeperBoard(int rows, int cols, int numMines)
rows
- the number of rows on the boardcols
- the number of columns on the boardnumMines
- the number of mines to place on the boardMethod Detail |
public void flagCell(int row, int col)
flagCell
in class MineSweeperBoardBase
row
- the row of the cell to be flagged/unflagged.col
- the column of the cell to be flagged/unflagged.public boolean gameLost()
gameLost
in class MineSweeperBoardBase
public boolean gameWon()
gameWon
in class MineSweeperBoardBase
public int getCell(int row, int col)
getCell
in class MineSweeperBoardBase
row
- the row containing the cell (starting at zero)col
- the column containing the cell (starting at zero)
public int getColumns()
getColumns
in class MineSweeperBoardBase
public int getRows()
getRows
in class MineSweeperBoardBase
public int numAdjMines(int row, int col)
numAdjMines
in class MineSweeperBoardBase
row
- the row of the cell.col
- the column of the cell.
public void revealBoard()
revealBoard
in class MineSweeperBoardBase
protected void setCell(int row, int col, int value)
setCell
in class MineSweeperBoardBase
row
- the row containing the cellcol
- the column containing the cell
public void uncoverCell(int row, int col)
uncoverCell
in class MineSweeperBoardBase
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 |