Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.cpp
- #include <iostream>
- #include "XOBoard.h"
- int main()
- {
- XOBoard Board{ 3 };
- Board.printBoard();
- //std::cout << Board ;
- }
- Cell.h
- #pragma once
- class Cell {
- private:
- char ch;
- public:
- Cell(char ch = '.');
- char getCellValue();
- void setCellValue(char nch);
- };
- Cell.cpp
- #pragma once
- #include "Cell.h"
- #include <iostream>
- Cell::Cell(char ch) {
- if (ch == 'X' || ch == 'O' || ch == '.') {
- this->ch = ch;
- }
- else {
- this->ch = '.';
- }
- }
- char Cell::getCellValue() {
- if (this->ch)
- return this->ch;
- else
- return '0';
- }
- void Cell::setCellValue(char ch) {
- if (ch == 'X' || ch == 'O' || ch == '.') {
- this->ch = ch;
- }
- else {
- std::cout << "Error occurd!" << std::endl;
- }
- }
- XOBoard.h
- #pragma once
- #include "Cell.h"
- #include <iostream>
- class XOBoard {
- private:
- int n;
- Cell **Board;
- public:
- XOBoard(int n = 3);
- void printBoard();
- /*friend std::ostream& operator<<(std::ostream& output, const XOBoard& XOBoard) {
- for (int i = 0; i < XOBoard.n; i++) {
- for (int j = 0; j < XOBoard.n; j++) {
- output << XOBoard.Board[i][j].getCellValue();
- }
- output << std::endl;
- }
- return output;
- }*/
- };
- XOBoard.cpp
- #pragma once
- #include "Cell.h"
- #include "XOBoard.h"
- #include <iostream>
- XOBoard::XOBoard(int n) {
- this->n = (n >= 3) ? n : 3;
- Cell** Board = new Cell*[n];
- for (int i = 0; i < n; i++) {
- Board[i] = new Cell[n];
- }
- }
- void XOBoard::printBoard() {
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- std::cout << Board[i][j].getCellValue() << '| ';
- }
- std::cout << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement