Package model

Class ClearCellGameModel


  • public class ClearCellGameModel
    extends GameModel
    This class extends GameModel and implements the logic of the clear cell game, specifically.
    Author:
    Dept of Computer Science, UMCP
    • Constructor Summary

      Constructors 
      Constructor Description
      ClearCellGameModel​(int rows, int cols, java.util.Random random)
      Defines a board with empty cells.
    • Constructor Detail

      • ClearCellGameModel

        public ClearCellGameModel​(int rows,
                                  int cols,
                                  java.util.Random random)
        Defines a board with empty cells. It relies on the super class constructor to define the board.
        Parameters:
        rows - number of rows in board
        cols - number of columns in board
        random - random number generator to be used during game when rows are randomly created
    • Method Detail

      • isGameOver

        public boolean isGameOver()
        The game is over when the last row (the one with index equal to board.length -1) contains at least one cell that is not empty.
        Specified by:
        isGameOver in class GameModel
      • getScore

        public int getScore()
        Returns the player's score. The player should be awarded one point for each cell that is cleared.
        Specified by:
        getScore in class GameModel
        Returns:
        player's score
      • nextAnimationStep

        public void nextAnimationStep()
        This method must do nothing in the case where the game is over. As long as the game is not over yet, this method will do the following: 1. Shift the existing rows down by one position. 2. Insert a row of random BoardCell objects at the top of the board. The row will be filled from left to right with cells obtained by calling BoardCell.getNonEmptyRandomBoardCell(). (The Random number generator passed to the constructor of this class should be passed as the argument to this method call.)
        Specified by:
        nextAnimationStep in class GameModel
      • processCell

        public void processCell​(int rowIndex,
                                int colIndex)
        This method is called when the user clicks a cell on the board. If the selected cell is not empty, it will be set to BoardCell.EMPTY, along with any adjacent cells that are the same color as this one. (This includes the cells above, below, to the left, to the right, and all in all four diagonal directions.) If any rows on the board become empty as a result of the removal of cells then those rows will "collapse", meaning that all non-empty rows beneath the collapsing row will shift upward.
        Specified by:
        processCell in class GameModel
        Parameters:
        rowIndex - row that user has clicked
        colIndex - column that user has clicked
        Throws:
        java.lang.IllegalArgumentException - with message "Invalid row index" for invalid row or "Invalid column index" for invalid column. We check for row validity first.