Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. package model;
  2.  
  3. /**
  4. * This class represents the logic of a game where a board is updated on each
  5. * step of the game animation. The board can also be updated by selecting a
  6. * board cell.
  7. *
  8. * @author Dept of Computer Science, UMCP
  9. */
  10.  
  11. public abstract class Game
  12. {
  13. protected BoardCell[][] board;
  14.  
  15. /**
  16. * Defines a board with BoardCell.EMPTY cells.
  17. *
  18. * @param maxRows
  19. * @param maxCols
  20. */
  21. public Game(int maxRows, int maxCols)
  22. {
  23. board = new BoardCell[maxRows][maxCols];
  24. }
  25. public int getMaxRows()
  26. {
  27. return board.length;
  28. }
  29. public int getMaxCols()
  30. {
  31. return board[0].length;
  32. }
  33. public void setBoardCell(int rowIndex, int colIndex, BoardCell boardCell)
  34. {
  35. board[rowIndex][colIndex] = boardCell;
  36. }
  37. public BoardCell getBoardCell(int rowIndex, int colIndex)
  38. {
  39. return board[rowIndex][colIndex];
  40. }
  41. /**
  42. * Initializes row with the specified color.
  43. * @param rowIndex
  44. * @param cell
  45. */
  46. public void setRowWithColor(int rowIndex, BoardCell cell)
  47. {
  48. for (int x = 0;x < board[0].length;x++)
  49. {
  50. board[rowIndex][x] = cell;
  51. }
  52. }
  53. /**
  54. * Initializes column with the specified color.
  55. * @param colIndex
  56. * @param cell
  57. */
  58. public void setColWithColor(int colIndex, BoardCell cell)
  59. {
  60. for (int x = 0;x < board.length;x++)
  61. {
  62. board[x][colIndex] = cell;
  63. }
  64. }
  65. /**
  66. * Initializes the board with the specified color.
  67. * @param cell
  68. */
  69. public void setBoardWithColor(BoardCell cell)
  70. {
  71. for (int rows = 0;rows < board.length;rows++)
  72. {
  73. for (int cols = 0;cols < board[0].length;cols++)
  74. {
  75. board[rows][cols] = cell;
  76. }
  77. }
  78. }
  79. public abstract boolean isGameOver();
  80. public abstract int getScore();
  81. /**
  82. * Advances the animation one step.
  83. */
  84. public abstract void nextAnimationStep();
  85. /**
  86. * Adjust the board state according to the current board state and the
  87. * selected cell.
  88. *
  89. * @param rowIndex
  90. * @param colIndex
  91. */
  92. public abstract void processCell(int rowIndex, int colIndex);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement