Advertisement
sheredega

Task #16

Dec 10th, 2022
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     char arr[3][3];
  6.     int n = 1;
  7.     int x, y;
  8.     bool turn = true;
  9.     cout << "Our gamezone now:\n";
  10.     for (int i = 0; i < 3; i++) {
  11.         for (int j = 0; j < 3; j++) {
  12.             arr[i][j] = '-';
  13.             cout << arr[i][j] << " ";
  14.         }
  15.         cout << endl;
  16.     }
  17.  
  18.  
  19.     while (n <= 9) {
  20.         cout << "\nWrite cords (example: 0 2 or 1 1): ";
  21.         cin >> x;
  22.         cin >> y;
  23.         if (arr[x][y] == '-') {
  24.             turn ? arr[x][y] = 'X' : arr[x][y] = '0';
  25.             turn ? turn = false : turn = true;
  26.         }
  27.         else {
  28.             cout << "Wrong cords! Try again!";
  29.             continue;
  30.         }
  31.         cout << "Our gamezone now:\n";
  32.         for (int i = 0; i < 3; i++) {
  33.             for (int j = 0; j < 3; j++) {
  34.                 cout << arr[i][j] << " ";
  35.             }
  36.             cout << endl;
  37.         }
  38.         if (arr[0][0] == arr[1][1] && arr[0][0] == arr[2][2] && arr[1][1] != '-') {
  39.             cout << "Winner - " << arr[1][1];
  40.             return 0;
  41.         }
  42.         if (arr[1][1] == arr[0][2] && arr[2][0] == arr[1][1] && arr[1][1] != '-') {
  43.             cout << "Winner - " << arr[1][1];
  44.             return 0;
  45.         }
  46.         for (int i = 0; i < 3; i++) {
  47.             if (arr[i][1] == arr[i][0] && arr[i][1] == arr[i][2] && arr[i][1] != '-') {
  48.                 cout << "Winner - " << arr[i][1];
  49.                 return 0;
  50.             }
  51.             if (arr[1][i] == arr[0][i] && arr[1][i] == arr[2][i] && arr[1][i] != '-') {
  52.                 cout << "Winner - " << arr[1][i];
  53.                 return 0;
  54.             }
  55.         }
  56.         n++;
  57.     }
  58.     cout << "\nThe end! No one cant win";
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement