Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. int board[3][3], row, column, chosenRow, chosenColumn;
  6. bool condition = true;
  7.  
  8. void createEmptyBoard()
  9. {
  10.     for (row = 0; row < 3; row++)
  11.     {
  12.         for (column = 0; column < 3; column++)
  13.         {
  14.             board[row][column] = 0;
  15.         }
  16.     }
  17. }
  18.  
  19. void createBoard(){
  20.     cout << "+---+---+---+\n";
  21.     for (row = 0; row < 3; row++)
  22.     {
  23.         for (column = 0; column < 3; column++)
  24.         {
  25.  
  26.             if (board[row][column] == 0)
  27.             {
  28.                 cout << "|   ";
  29.             }
  30.  
  31.             if (board[row][column] == 1)
  32.             {
  33.                 cout << "| o ";
  34.             }
  35.  
  36.             if (board[row][column] == 2)
  37.             {
  38.                 cout << "| x ";
  39.             }
  40.             if (column == 2)
  41.             {
  42.                 cout << "|" << row + 1 << " ROW";
  43.                 cout << "\n+---+---+---+";
  44.             }
  45.         }
  46.         cout << "\n";
  47.     }
  48.     cout << "  1   2   3 \n   COLUMN";
  49. }
  50.  
  51. void noughtMove()
  52. {
  53.     condition = true;
  54.     while (condition)
  55.     {
  56.         cout << "\n\nChoose coordinates for a nought. \nSelect a row: ";
  57.         cin >> chosenRow;
  58.         cout << "Select a column: ";
  59.         cin >> chosenColumn;
  60.         chosenRow -= 1;
  61.         chosenColumn -= 1;
  62.  
  63.         if (board[chosenRow][chosenColumn] == 0 & (chosenRow < 3 || chosenColumn < 3))
  64.         {
  65.             board[chosenRow][chosenColumn] = 1;
  66.             condition = false;
  67.         }
  68.     }
  69. }
  70.  
  71. void crossMove()
  72. {
  73.     condition = true;
  74.     while (condition)
  75.     {
  76.         cout << "\n\nChoose coordinates for a cross. \nSelect a row: ";
  77.         cin >> chosenRow;
  78.         cout << "Select a column: ";
  79.         cin >> chosenColumn;
  80.         chosenRow -= 1;
  81.         chosenColumn -= 1;
  82.  
  83.  
  84.         if (board[chosenRow][chosenColumn] == 0 & (chosenRow < 3 || chosenColumn < 3))
  85.         {
  86.             board[chosenRow][chosenColumn] = 2;
  87.             condition = false;
  88.         }
  89.     }
  90.     condition = true;
  91. }
  92. int main()
  93. {
  94.  
  95.     createEmptyBoard();
  96.  
  97.     while (condition)
  98.     {
  99.         createBoard();
  100.         noughtMove();
  101.         system("CLS");
  102.         createBoard();
  103.         crossMove();
  104.         system("CLS");
  105.  
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement