Package model
Class GameModel
- java.lang.Object
-
- model.GameModel
-
- Direct Known Subclasses:
ClearCellGameModel
public abstract class GameModel extends java.lang.Object
This class represents the logic of a game where a board is updated on each step of the game animation. The board can also be updated by selecting a board cell.- Author:
- Dept of Computer Science, UMCP
-
-
Constructor Summary
Constructors Constructor Description GameModel(int rows, int cols)
Creates a rectangular board of the specified size, filling it with BoardCell.EMPTY cells.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BoardCell[][]
getBoard()
Returns a reference to the board without making any kind of copy.BoardCell
getBoardCell(int rowIndex, int colIndex)
Returns the value at a given location of the boardint
getCols()
Returns the number of columns on the boardint
getRows()
Returns the number of rows on the boardabstract int
getScore()
abstract boolean
isGameOver()
abstract void
nextAnimationStep()
Advances the animation one step.abstract void
processCell(int rowIndex, int colIndex)
Adjust the board state according to the current board state and the selected cell.void
setBoardCell(int rowIndex, int colIndex, BoardCell boardCell)
Sets the cell at the specified location to value provided.java.lang.String
toString()
Provides a string representation of the board We have implemented this method for you.
-
-
-
Method Detail
-
getRows
public int getRows()
Returns the number of rows on the board- Returns:
- number of rows
-
getCols
public int getCols()
Returns the number of columns on the board- Returns:
- number of columns
-
getBoard
public BoardCell[][] getBoard()
Returns a reference to the board without making any kind of copy.- Returns:
- the board
-
setBoardCell
public void setBoardCell(int rowIndex, int colIndex, BoardCell boardCell)
Sets the cell at the specified location to value provided.- Parameters:
rowIndex
- row to setcolIndex
- column to setboardCell
- value to assign to the board
-
getBoardCell
public BoardCell getBoardCell(int rowIndex, int colIndex)
Returns the value at a given location of the board- Parameters:
rowIndex
- row to accesscolIndex
- column to access- Returns:
- value of board at the specified location
-
toString
public java.lang.String toString()
Provides a string representation of the board We have implemented this method for you.- Overrides:
toString
in classjava.lang.Object
-
isGameOver
public abstract boolean isGameOver()
-
getScore
public abstract int getScore()
-
nextAnimationStep
public abstract void nextAnimationStep()
Advances the animation one step.
-
processCell
public abstract void processCell(int rowIndex, int colIndex)
Adjust the board state according to the current board state and the selected cell.- Parameters:
rowIndex
- row that user has clickedcolIndex
- column that user has clicked
-
-