Package model

Class 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 board
      int getCols()
      Returns the number of columns on the board
      int getRows()
      Returns the number of rows on the board
      abstract 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.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • GameModel

        public GameModel​(int rows,
                         int cols)
        Creates a rectangular board of the specified size, filling it with BoardCell.EMPTY cells.
        Parameters:
        rows - number of rows on the board
        cols - number of columns on the board
    • 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 set
        colIndex - column to set
        boardCell - 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 access
        colIndex - 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 class java.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 clicked
        colIndex - column that user has clicked