Advertisement
avr39ripe

cubesGameFix

Oct 28th, 2020
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3.  
  4. int main()
  5. {
  6.     const int div{2}; // count of players to calculate turn number from i
  7.     int drop{ 0 };
  8.     int playerSum{ 0 };
  9.     int computerSum{ 0 };
  10.     char space{ ' ' };
  11.     const int minValue{ 1 };
  12.     const int maxValue{ 6 };
  13.     bool comp{false}; // who drops cubes true - comp, false - human :)
  14.     srand(time(0));
  15.  
  16.     std::cout << "Hello. We'll play a game \"Cubes\".\nOne by one we will drop two play cubes, who will have the biggest sum in three drops will win!!! Good luck!!!\n\n";
  17.  
  18.     for (int i{ 1 }; i <= 6; comp=!comp, ++i)
  19.     {
  20.         std::cout << (comp ? "My " : "You ") << "drop No." << ((i / div) + ( i % div )) << "\nPress \""<< (comp ? 'c' : 'd') << "\" to drop cube ---> ";
  21.         std::cin >> space;
  22.  
  23.         while (space != (comp ? 'c' : 'd'))
  24.         {
  25.             std::cout << "Oops, wrong key! Try again ---> ";
  26.             std::cin >> space;
  27.         }
  28.  
  29.  
  30.         for (int i{ 0 }; i < 2; ++i)
  31.         {
  32.             drop = rand() % (maxValue - 1) + minValue;
  33.             if (drop == 1) { std::cout << "* * * * *\n*       *\n*   #   *\n*       *\n* * * * *\n\n"; }
  34.             else if (drop == 2) { std::cout << "* * * * *\n*  #    *\n*       *\n*    #  *\n* * * * *\n\n"; }
  35.             else if (drop == 3) { std::cout << "* * * * *\n*  #    *\n*   #   *\n*    #  *\n* * * * *\n\n"; }
  36.             else if (drop == 4) { std::cout << "* * * * *\n* #   # *\n*       *\n* #   # *\n* * * * *\n\n"; }
  37.             else if (drop == 5) { std::cout << "* * * * *\n* #   # *\n*   #   *\n* #   # *\n* * * * *\n\n"; }
  38.             else if (drop == 6) { std::cout << "* * * * *\n* #   # *\n* #   # *\n* #   # *\n* * * * *\n\n"; }
  39.             comp ? computerSum+= drop : playerSum += drop;
  40.         }
  41.  
  42.         std::cout << (comp ? "My " : "You ") << "count is " << (comp ? computerSum : playerSum) << "\n\n";
  43.  
  44.     }
  45.  
  46.     if (playerSum > computerSum)
  47.     {
  48.         std::cout << "Congratulations!!! You are the winner!! You have " << playerSum << " while I have just " << computerSum << "\n\n";
  49.     }
  50.     else if (playerSum < computerSum)
  51.     {
  52.         std::cout << "I'm sorry =( I am the winner!! You have just " << playerSum << " while I have " << computerSum << "\n\n";
  53.     }
  54.     else if (playerSum == computerSum)
  55.     {
  56.         std::cout << "Today it's draw!! Congrats! We both have " << playerSum << "\n\n";
  57.     }
  58.  
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement