Advertisement
Maco153

Constructor and destructor for the board class

Feb 13th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. Board::Board(int c1r, int c1c, int c2r, int c2c) {
  2.     cout << "Enter the size of the board between 9 and 12\n";
  3.     cin >> boardSize;
  4.     if (!validSize(boardSize)) {
  5.         cout << "Invalid Entered Size\n";
  6.         exit(1);
  7.     }
  8.     board = new char* [boardSize];
  9.     for (int i = 0; i < boardSize; i++) {
  10.         *(board + i) = new char[boardSize];
  11.     }
  12.     for (int i = 0; i < boardSize; i++) {
  13.         for (int j = 0; j < boardSize; j++) {
  14.             *(*(board + i) + j) = '-';
  15.         }
  16.     }
  17.     *(*(board + c1r) + c1c) = 'C';
  18.     *(*(board + c2r) + c2c) = 'C'; // Represents the two cats
  19.     *(*(board + (boardSize / 2)) + boardSize - 1) = 'B'; // Assuming that when there are two rows which is middle, we take the least one
  20.  
  21.  
  22. }
  23.  
  24. Board::~Board() {
  25.     for (int i = 0; i < boardSize; i++) {
  26.         delete[] * (board + i);
  27.     }
  28.     delete[] board;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement