Advertisement
Rika_Z

xo game

Jul 23rd, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #if defined(_WIN32) || defined(_WIN64)
  6. #pragma execution_character_set("utf-8")
  7. #include<Windows.h>
  8. const auto _dummy_ = []()
  9. {
  10.     SetConsoleCP(65001);
  11.     SetConsoleOutputCP(65001);
  12.     return 0;
  13. }();
  14. #endif
  15. using namespace std;
  16. int main()
  17. {
  18.     srand(static_cast<unsigned int>(time(0)));
  19.     int lever1 = 1;
  20.     bool lever2 = false;
  21.     char xo1 = '_';
  22.     char xo2 = '_';
  23.     char xo3 = '_';
  24.     char xo4 = '_';
  25.     char xo5 = '_';
  26.     char xo6 = '_';
  27.     char xo7 = '_';
  28.     char xo8 = '_';
  29.     char xo9 = '_';
  30.     while (lever1 != 0)
  31.     {
  32.         int cell1 = 1;
  33.         int cell2 = 2;
  34.         int cell3 = 3;
  35.         int cell4 = 4;
  36.         int cell5 = 5;
  37.         int cell6 = 6;
  38.         int cell7 = 7;
  39.         int cell8 = 8;
  40.         int cell9 = 9;
  41.         cout << cell1 << "|";
  42.         cout << xo1 << "|";
  43.         cout << cell2 << "|";
  44.         cout << xo2 << "|";
  45.         cout << cell3 << "|";
  46.         cout << xo3 << "|";
  47.         cout << "\n" << cell4 << "|";
  48.         cout << xo4 << "|";
  49.         cout << cell5 << "|";
  50.         cout << xo5 << "|";
  51.         cout << cell6 << "|";
  52.         cout << xo6 << "|";
  53.         cout << "\n" << cell7 << "|";
  54.         cout << xo7 << "|";
  55.         cout << cell8 << "|";
  56.         cout << xo8 << "|";
  57.         cout << cell9 << "|";
  58.         cout << xo9 << "|\n";
  59.         if (lever2 == true)
  60.         {
  61.             cout << "конец игры\n";
  62.             lever1 = 0;
  63.         }
  64.         cout << "Выберите номер ячейки\n";
  65.         int number;
  66.         cin >> number;
  67.         switch (number)
  68.         {
  69.         case 1:
  70.             cout << "'x' или 'o'\n";
  71.             cin >> xo1;
  72.             break;
  73.         case 2:
  74.             cout << "'x' или 'o'\n";
  75.             cin >> xo2;
  76.             break;
  77.         case 3:
  78.             cout << "'x' или 'o'\n";
  79.             cin >> xo3;
  80.             break;
  81.         case 4:
  82.             cout << "'x' или 'o'\n";
  83.             cin >> xo4;
  84.             break;
  85.         case 5:
  86.             cout << "'x' или 'o'\n";
  87.             cin >> xo5;
  88.             break;
  89.         case 6:
  90.             cout << "'x' или 'o'\n";
  91.             cin >> xo6;
  92.             break;
  93.         case 7:
  94.             cout << "'x' или 'o'\n";
  95.             cin >> xo7;
  96.             break;
  97.         case 8:
  98.             cout << "'x' или 'o'\n";
  99.             cin >> xo8;
  100.             break;
  101.         case 9:
  102.             cout << "'x' или 'o'\n";
  103.             cin >> xo9;
  104.             break;
  105.         }
  106.         if ((xo1 == 'x' && xo2 == 'x' && xo3 == 'x') || (xo1 == 'x'
  107.             && xo4 == 'x' && xo7 == 'x') || (xo1 == 'x' && xo5 == 'x' && xo9 == 'x'))
  108.         {
  109.             cout << "x выиграл\n";
  110.             lever2 == true;
  111.         }
  112.         else if ((xo2 == 'x' && xo5 == 'x' && xo8 == 'x') || (xo4 == 'x' && xo5 == 'x' && xo6 == 'x'))
  113.         {
  114.             cout << "x выиграл\n";
  115.             lever2 == true;
  116.         }
  117.         else if ((xo3 == 'x' && xo5 == 'x' && xo7 == 'x') || (xo3 == 'x' && xo6 == 'x'
  118.             && xo9 == 'x') || (xo7 == 'x' && xo8 == 'x' && xo9 == 'x'))
  119.         {
  120.             cout << "x выиграл\n";
  121.             lever2 == true;
  122.         }
  123.          else if ((xo1 == 'o' && xo2 == 'o' && xo3 == 'o') || (xo1 == 'o'
  124.             && xo4 == 'o' && xo7 == 'o') || (xo1 == 'o' && xo5 == 'o' && xo9 == 'o'))
  125.         {
  126.             cout << "o выиграл\n";
  127.             lever2 == true;
  128.         }
  129.         else if ((xo2 == 'o' && xo5 == 'o' && xo8 == 'o') || (xo4 == 'o' && xo5 == 'o' && xo6 == 'o'))
  130.         {
  131.             cout << "o выиграл\n";
  132.             lever2 == true;
  133.         }
  134.         else if ((xo3 == 'o' && xo5 == 'o' && xo7 == 'o') || (xo3 == 'o' && xo6 == 'o'
  135.             && xo9 == 'o') || (xo7 == 'o' && xo8 == 'o' && xo9 == 'o'))
  136.         {
  137.             cout << "o выиграл\n";
  138.             lever2 == true;
  139.         }
  140.     }
  141.     return 0;
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement