SHARE
TWEET

Untitled

a guest Dec 11th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. main.cpp
  2.  
  3. #include <iostream>
  4. #include "XOBoard.h"
  5. int main()
  6. {
  7.     XOBoard Board{ 3 };
  8.     Board.printBoard();
  9.     //std::cout << Board ;
  10. }
  11.  
  12.  
  13.  
  14. Cell.h
  15.  
  16. #pragma once
  17.  
  18. class Cell {
  19.     private:
  20.         char ch;
  21.     public:
  22.         Cell(char ch = '.');
  23.         char getCellValue();
  24.         void setCellValue(char nch);
  25. };
  26.  
  27.  
  28.  
  29. Cell.cpp
  30.  
  31. #pragma once
  32. #include "Cell.h"
  33. #include <iostream>
  34.  
  35. Cell::Cell(char ch) {
  36.     if (ch == 'X' || ch == 'O' || ch == '.') {
  37.         this->ch = ch;
  38.     }
  39.     else {
  40.         this->ch = '.';
  41.     }
  42. }
  43. char Cell::getCellValue() {
  44.     if (this->ch)
  45.         return  this->ch;
  46.     else
  47.         return '0';
  48. }
  49. void Cell::setCellValue(char ch) {
  50.     if (ch == 'X' || ch == 'O' || ch == '.') {
  51.         this->ch = ch;
  52.     }
  53.     else {
  54.         std::cout << "Error occurd!" << std::endl;
  55.     }
  56. }
  57.  
  58. XOBoard.h
  59.  
  60. #pragma once
  61. #include "Cell.h"
  62. #include <iostream>
  63.  
  64. class XOBoard {
  65.     private:
  66.         int n;
  67.         Cell **Board;
  68.     public:
  69.         XOBoard(int n = 3);
  70.         void printBoard();
  71.         /*friend std::ostream& operator<<(std::ostream& output, const XOBoard& XOBoard) {
  72.             for (int i = 0; i < XOBoard.n; i++) {
  73.                 for (int j = 0; j < XOBoard.n; j++) {
  74.                     output << XOBoard.Board[i][j].getCellValue();
  75.                 }
  76.                 output << std::endl;
  77.             }
  78.             return output;
  79.         }*/
  80. };
  81.  
  82.  
  83. XOBoard.cpp
  84.  
  85. #pragma once
  86. #include "Cell.h"
  87. #include "XOBoard.h"
  88. #include <iostream>
  89.  
  90. XOBoard::XOBoard(int n) {
  91.     this->n = (n >= 3) ? n : 3;
  92.     Cell** Board = new Cell*[n];
  93.     for (int i = 0; i < n; i++) {
  94.         Board[i] = new Cell[n];
  95.     }
  96. }
  97.  
  98. void XOBoard::printBoard() {
  99.     for (int i = 0; i < n; i++) {
  100.         for (int j = 0; j < n; j++) {
  101.             std::cout << Board[i][j].getCellValue() << '|  ';
  102.         }
  103.         std::cout << std::endl;
  104.     }
  105. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top