GarikK

Игра крестики нолики(начало)

Mar 11th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.86 KB | None | 0 0
  1. // 11.03.2020.cpp:
  2. //
  3.  
  4. #include <iostream>
  5. using namespace std;
  6. int main()
  7. {
  8.     //creating array
  9.     char myArray[3][3];
  10.     for (int x = 0; x < 3; x++)
  11.     {
  12.         for (int y = 0; y < 3; y++)
  13.         {
  14.             myArray[x][y] = ' ';
  15.         }
  16.     }
  17.     bool isWin = false;
  18.  
  19.     while (!isWin)
  20.     {
  21.     enter_coordinates:
  22.         cout << "Please enter X:" << endl;
  23.         int userX = 0;
  24.         cin >> userX;
  25.         cout << "Please enter Y:" << endl;
  26.         int userY = 0;
  27.         cin >> userY;
  28.         if (!(userX < 3) && (userX < 0))
  29.         {
  30.             cout << "Wrong coordinates!" << endl;
  31.             goto enter_coordinates;
  32.         }
  33.  
  34.         if (!(userY < 3) && (userY < 0))
  35.         {
  36.             cout << "Wrong coordinates!" << endl;
  37.             goto enter_coordinates;
  38.         }
  39.         if (myArray[userX][userY] != ' ')
  40.         {
  41.             cout << "There is " << myArray[userX][userY] << " already in this point" << endl;
  42.             goto enter_coordinates;
  43.         }
  44.         else if (myArray[userX][userY] == ' ')
  45.         {
  46.             myArray[userX][userY] = 'X';
  47.         }
  48.         //---
  49.         cout << endl;
  50.         for (int y = 0; y < 3; y++)
  51.         {
  52.             for (int x = 0; x < 3; x++)
  53.             {
  54.                 char outChar = myArray[x][y];
  55.                 if (outChar == ' ')
  56.                 {
  57.                     outChar = '_';
  58.                 }
  59.                 cout << outChar << ' ';
  60.             }
  61.             cout << endl;
  62.         }
  63.  
  64.         if (myArray[0][0] == 'X' && myArray[1][0] == 'X' && myArray[2][0] == 'X')isWin = true;//1
  65.         if (myArray[0][0] == 'X' && myArray[0][1] == 'X' && myArray[0][2] == 'X')isWin = true;
  66.         if (myArray[0][1] == 'X' && myArray[1][1] == 'X' && myArray[2][1] == 'X')isWin = true;
  67.         if (myArray[0][2] == 'X' && myArray[1][2] == 'X' && myArray[2][2] == 'X')isWin = true;
  68.         if (myArray[1][0] == 'X' && myArray[1][1] == 'X' && myArray[1][2] == 'X')isWin = true;
  69.         if (myArray[2][0] == 'X' && myArray[2][1] == 'X' && myArray[2][2] == 'X')isWin = true;
  70.         if (myArray[0][2] == 'X' && myArray[1][1] == 'X' && myArray[2][0] == 'X')isWin = true;
  71.         if (myArray[0][0] == 'X' && myArray[1][1] == 'X' && myArray[2][2] == 'X')isWin = true;
  72.     }
  73. }
Add Comment
Please, Sign In to add comment