Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- #pragma region
- void print(string text);
- void printBoard(int arr[][3], int sizeX, int sizeY);
- void drawBoard(char arr[][3]);
- void inputNumbers(int _input, int logicBoard[][3], int _pl, int _round);
- void boardManager();
- void visualMng(int _input, char _board[][3], char _pl, int _round);
- #pragma endregion
- int main() {
- boardManager();
- cin.get();
- cin.get();
- }
- #pragma region
- void print(string text)
- {
- cout << text << endl;
- }
- void printBoard(int arr[][3], int sizeX, int sizeY)
- {
- for (int y = 0; y < sizeY; y++)
- {
- for (int x = 0; x < sizeX; x++)
- {
- cout << arr[x][y] << " ";
- }
- cout << endl;
- }
- }
- void drawBoard(char arr[][3]) {
- print(" | | ");
- cout << " " << arr[0][0] << " | " << arr[1][0] << " | " << arr[2][0] << endl;
- print("_____|_____|_____");
- print(" | | ");
- cout << " " << arr[0][1] << " | " << arr[1][1] << " | " << arr[2][1] << endl;
- print("_____|_____|_____");
- print(" | | ");
- cout << " " << arr[0][2] << " | " << arr[1][2] << " | " << arr[2][2] << endl;
- print(" | | ");
- }
- #pragma endregion
- bool verticalX(int arr[][3]) {
- bool verticalX = false;
- for (int x = 0; x < 3; x++)
- {
- if (arr[x][0] + arr[x][1] + arr[x][2] == 3) {
- verticalX = true;
- }
- }
- return verticalX;
- }
- bool verticalO(int arr[][3]) {
- bool verticalO = false;
- for (int x = 0; x < 3; x++)
- {
- if (arr[x][0] + arr[x][1] + arr[x][2] == 6) {
- verticalO = true;
- }
- }
- return verticalO;
- }
- bool horizonalX(int arr[][3])
- {
- bool horizontalX = false;
- for (int y = 0; y < 3; y++)
- {
- if (arr[0][y] + arr[1][y] + arr[2][y] == 3) {
- horizontalX = true;
- }
- }
- return horizontalX;
- }
- bool horizonalO(int arr[][3])
- {
- bool horizontalO = false;
- for (int y = 0; y < 3; y++)
- {
- if (arr[0][y] + arr[1][y] + arr[2][y] == 6) {
- horizontalO = true;
- }
- }
- return horizontalO;
- }
- bool diagonalZX(int arr[][3])
- {
- bool diagonalZX = false;
- if (arr[0][0] + arr[1][1] + arr[2][2] == 3 || arr[2][0] + arr[1][1] + arr[0][2] == 3)
- diagonalZX = true;
- return diagonalZX;
- }
- bool diagonalZO(int arr[][3])
- {
- bool diagonalZO = false;
- if (arr[0][0] + arr[1][1] + arr[2][2] == 6 || arr[2][0] + arr[1][1] + arr[0][2] == 6)
- diagonalZO = true;
- return diagonalZO;
- }
- void inputNumbers(int _input, int logicBoard[][3], int _pl, int _round)
- {
- bool gameOn = true;
- switch (_input)
- {
- case 1:
- if (_round % 2 == 0)
- {
- if (logicBoard[0][2] != 1 || logicBoard[0][2] != 2)
- logicBoard[0][2] = 1;
- break;
- }
- else {
- if (logicBoard[0][2] != 1 || logicBoard[0][2] != 2)
- logicBoard[0][2] = 2;
- break;
- }
- case 2:
- if (_round % 2 == 0)
- {
- if (logicBoard[1][2] != 1 || logicBoard[1][2] != 2)
- logicBoard[1][2] = 1;
- break;
- }
- else {
- if (logicBoard[1][2] != 1 || logicBoard[1][2] != 2)
- logicBoard[1][2] = 2;
- break;
- }
- case 3:
- if (_round % 2 == 0)
- {
- if (logicBoard[2][2] != 1 || logicBoard[2][2] != 2)
- logicBoard[2][2] = 1;
- break;
- }
- else {
- if (logicBoard[2][2] != 1 || logicBoard[2][2] != 2)
- logicBoard[2][2] = 2;
- break;
- }
- case 4:
- if (_round % 2 == 0)
- {
- if (logicBoard[0][1] != 1 || logicBoard[0][1] != 2)
- logicBoard[0][1] = 1;
- break;
- }
- else {
- if (logicBoard[0][1] != 1 || logicBoard[0][1] != 2)
- logicBoard[0][1] = 2;
- break;
- }
- case 5:
- if (_round % 2 == 0)
- {
- if (logicBoard[1][1] != 1 || logicBoard[1][1] != 2)
- logicBoard[1][1] = 1;
- break;
- }
- else {
- if (logicBoard[1][1] != 1 || logicBoard[1][1] != 2)
- logicBoard[1][1] = 2;
- break;
- }
- case 6:
- if (_round % 2 == 0)
- {
- if (logicBoard[2][1] != 1 || logicBoard[2][1] != 2)
- logicBoard[2][1] = 1;
- break;
- }
- else {
- if (logicBoard[2][1] != 1 || logicBoard[2][1] != 2)
- logicBoard[2][1] = 2;
- break;
- }
- case 7:
- if (_round % 2 == 0)
- {
- if (logicBoard[0][0] != 1 || logicBoard[0][0] != 2)
- logicBoard[0][0] = 1;
- break;
- }
- else {
- if (logicBoard[0][0] != 1 || logicBoard[0][0] != 2)
- logicBoard[0][0] = 2;
- break;
- }
- case 8:
- if (_round % 2 == 0)
- {
- if (logicBoard[1][0] != 1 || logicBoard[1][0] != 2)
- logicBoard[1][0] = 1;
- break;
- }
- else {
- if (logicBoard[1][0] != 1 || logicBoard[1][0] != 2)
- logicBoard[1][0] = 2;
- break;
- }
- case 9:
- if (_round % 2 == 0)
- {
- if (logicBoard[2][0] != 1 || logicBoard[2][0] != 2)
- logicBoard[2][0] = 1;
- break;
- }
- else {
- if (logicBoard[2][0] != 1 || logicBoard[2][0] != 2)
- logicBoard[2][0] = 2;
- break;
- }
- default:
- break;
- }
- }
- void visualMng(int _input, char _board[][3], char _pl, int _round)
- {
- int endRound = 1;
- bool nextRound = true;
- while (nextRound) {
- switch (_input)
- {
- case 1:
- if (_round > 1) {
- if (_board[0][2] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[0][2] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[0][2] = _pl;
- system("cls");
- endRound++;
- }
- break;
- case 2:
- if (_round > 1) {
- if (_board[1][2] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[1][2] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[1][2] = _pl;
- system("cls");
- endRound++;
- }
- break;
- case 3:
- if (_round > 1) {
- if (_board[2][2] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[2][2] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[2][2] = _pl;
- system("cls");
- endRound++;
- }
- break;
- case 4:
- if (_round > 1) {
- if (_board[0][1] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[0][1] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[0][1] = _pl;
- system("cls");
- endRound++;
- }
- break;
- case 5:
- if (_round > 1) {
- if (_board[1][1] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[1][1] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[1][1] = _pl;
- system("cls");
- endRound++;
- }
- break;
- case 6:
- if (_round > 1) {
- if (_board[2][1] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[2][1] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[2][1] = _pl;
- system("cls");
- endRound++;
- }
- break;
- case 7:
- if (_round > 1) {
- if (_board[0][0] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[0][0] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[0][0] = _pl;
- system("cls");
- endRound++;
- }
- break;
- case 8:
- if (_round > 1) {
- if (_board[1][0] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[1][0] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[1][0] = _pl;
- system("cls");
- endRound++;
- }
- break;
- case 9:
- if (_round > 1) {
- if (_board[2][0] != ' ')
- {
- print("Position already taken :) Enter different position: ");
- nextRound = false;
- }
- else {
- _board[2][0] = _pl;
- system("cls");
- endRound++;
- }
- }
- else {
- _board[2][0] = _pl;
- system("cls");
- endRound++;
- }
- break;
- default:
- break;
- }
- if (nextRound = false)
- {
- cin >> _input;
- }
- }
- }
- void boardManager() {
- char visualBoard[3][3];
- int logicBoard[3][3];
- char p1;
- char p2;
- int logicalP1;
- int logicalP2;
- int input;
- int round = 0;
- bool gameState = false;
- //creates visual board
- for (int x = 0; x < 3; x++)
- {
- for (int y = 0; y < 3; y++)
- {
- visualBoard[x][y] = ' ';
- }
- }
- //creates logical board
- for (int x = 0; x < 3; x++)
- {
- for (int y = 0; y < 3; y++)
- {
- logicBoard[x][y] = 0;
- }
- }
- //chooses player side
- print("Player 1 is X you may begin to play now.");
- p1 = 'X';
- p2 = 'O';
- logicalP1 = 1;
- logicalP2 = 2;
- system("cls");
- drawBoard(visualBoard);
- print("Use numpad on your keyboard to play the game, when you choose your destination press enter.");
- while (gameState = false)
- {
- cin >> input;
- if (round % 2 == 0) {
- print("Player 1's turn:");
- visualMng(input, visualBoard, p1, round);
- inputNumbers(input, logicBoard, logicalP1, round);
- }
- else {
- print("Player 2's turn");
- visualMng(input, visualBoard, p2, round);
- inputNumbers(input, logicBoard, logicalP2, round);
- }
- drawBoard(visualBoard);
- print("Use numpad on your keyboard to play the game, when you choose your destination press enter.");
- round++;
- gameState = verticalX(logicBoard);
- if (gameState = true)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement