|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectmodel.GameModel
model.ClearCellGameModel
public class ClearCellGameModel
This class extends GameModel and implements the logic of the clear cell game. We define an empty cell as BoardCell.EMPTY. An empty row is defined as one where every cell corresponds to BoardCell.EMPTY.
| Constructor Summary | |
|---|---|
ClearCellGameModel(int maxRows,
int maxCols,
java.util.Random random)
Defines a board with empty cells. |
|
| Method Summary | |
|---|---|
int |
getScore()
Returns the game score. |
boolean |
isGameOver()
The game is over when the last board row (row with index board.length -1) is different from empty row. |
void |
nextAnimationStep()
This method will attempt to insert a row of random BoardCell objects at the top of the board (row with index 0) if the last board row (row with index board.length -1) corresponds to the empty row; Otherwise no operation will take place. |
void |
processCell(int rowIndex,
int colIndex)
This method will turn to BoardCell.EMPTY any cells adjacent (surrounding) the cell at position [rowIndex][colIndex] if and only if those adjacent cells have the same color as the selected cell. |
| Methods inherited from class model.GameModel |
|---|
getBoardCell, getMaxCols, getMaxRows, setBoardCell, toString |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ClearCellGameModel(int maxRows,
int maxCols,
java.util.Random random)
maxRows - maxCols - random - | Method Detail |
|---|
public boolean isGameOver()
isGameOver in class GameModelpublic int getScore()
getScore in class GameModelpublic void nextAnimationStep()
nextAnimationStep in class GameModel
public void processCell(int rowIndex,
int colIndex)
processCell in class GameModeljava.lang.IllegalArgumentException - with message "Invalid row index" for invalid row
or "Invalid column index" for invalid column. We check for row validity first.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||