Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "pch.h"
- #include <iostream>
- using namespace std;
- int board[3][3], row, column, chosenRow, chosenColumn;
- bool condition = true;
- void createEmptyBoard()
- {
- for (row = 0; row < 3; row++)
- {
- for (column = 0; column < 3; column++)
- {
- board[row][column] = 0;
- }
- }
- }
- void createBoard(){
- cout << "+---+---+---+\n";
- for (row = 0; row < 3; row++)
- {
- for (column = 0; column < 3; column++)
- {
- if (board[row][column] == 0)
- {
- cout << "| ";
- }
- if (board[row][column] == 1)
- {
- cout << "| o ";
- }
- if (board[row][column] == 2)
- {
- cout << "| x ";
- }
- if (column == 2)
- {
- cout << "|" << row + 1 << " ROW";
- cout << "\n+---+---+---+";
- }
- }
- cout << "\n";
- }
- cout << " 1 2 3 \n COLUMN";
- }
- void noughtMove()
- {
- condition = true;
- while (condition)
- {
- cout << "\n\nChoose coordinates for a nought. \nSelect a row: ";
- cin >> chosenRow;
- cout << "Select a column: ";
- cin >> chosenColumn;
- chosenRow -= 1;
- chosenColumn -= 1;
- if (board[chosenRow][chosenColumn] == 0 & (chosenRow < 3 || chosenColumn < 3))
- {
- board[chosenRow][chosenColumn] = 1;
- condition = false;
- }
- }
- }
- void crossMove()
- {
- condition = true;
- while (condition)
- {
- cout << "\n\nChoose coordinates for a cross. \nSelect a row: ";
- cin >> chosenRow;
- cout << "Select a column: ";
- cin >> chosenColumn;
- chosenRow -= 1;
- chosenColumn -= 1;
- if (board[chosenRow][chosenColumn] == 0 & (chosenRow < 3 || chosenColumn < 3))
- {
- board[chosenRow][chosenColumn] = 2;
- condition = false;
- }
- }
- condition = true;
- }
- int main()
- {
- createEmptyBoard();
- while (condition)
- {
- createBoard();
- noughtMove();
- system("CLS");
- createBoard();
- crossMove();
- system("CLS");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement