Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package model;
- /**
- * 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
- */
- public abstract class Game
- {
- protected BoardCell[][] board;
- /**
- * Defines a board with BoardCell.EMPTY cells.
- *
- * @param maxRows
- * @param maxCols
- */
- public Game(int maxRows, int maxCols)
- {
- board = new BoardCell[maxRows][maxCols];
- }
- public int getMaxRows()
- {
- return board.length;
- }
- public int getMaxCols()
- {
- return board[0].length;
- }
- public void setBoardCell(int rowIndex, int colIndex, BoardCell boardCell)
- {
- board[rowIndex][colIndex] = boardCell;
- }
- public BoardCell getBoardCell(int rowIndex, int colIndex)
- {
- return board[rowIndex][colIndex];
- }
- /**
- * Initializes row with the specified color.
- * @param rowIndex
- * @param cell
- */
- public void setRowWithColor(int rowIndex, BoardCell cell)
- {
- for (int x = 0;x < board[0].length;x++)
- {
- board[rowIndex][x] = cell;
- }
- }
- /**
- * Initializes column with the specified color.
- * @param colIndex
- * @param cell
- */
- public void setColWithColor(int colIndex, BoardCell cell)
- {
- for (int x = 0;x < board.length;x++)
- {
- board[x][colIndex] = cell;
- }
- }
- /**
- * Initializes the board with the specified color.
- * @param cell
- */
- public void setBoardWithColor(BoardCell cell)
- {
- for (int rows = 0;rows < board.length;rows++)
- {
- for (int cols = 0;cols < board[0].length;cols++)
- {
- board[rows][cols] = cell;
- }
- }
- }
- public abstract boolean isGameOver();
- public abstract int getScore();
- /**
- * Advances the animation one step.
- */
- public abstract void nextAnimationStep();
- /**
- * Adjust the board state according to the current board state and the
- * selected cell.
- *
- * @param rowIndex
- * @param colIndex
- */
- public abstract void processCell(int rowIndex, int colIndex);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement