Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- int main()
- {
- const int div{2}; // count of players to calculate turn number from i
- int drop{ 0 };
- int playerSum{ 0 };
- int computerSum{ 0 };
- char space{ ' ' };
- const int minValue{ 1 };
- const int maxValue{ 6 };
- bool comp{false}; // who drops cubes true - comp, false - human :)
- srand(time(0));
- 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";
- for (int i{ 1 }; i <= 6; comp=!comp, ++i)
- {
- std::cout << (comp ? "My " : "You ") << "drop No." << ((i / div) + ( i % div )) << "\nPress \""<< (comp ? 'c' : 'd') << "\" to drop cube ---> ";
- std::cin >> space;
- while (space != (comp ? 'c' : 'd'))
- {
- std::cout << "Oops, wrong key! Try again ---> ";
- std::cin >> space;
- }
- for (int i{ 0 }; i < 2; ++i)
- {
- drop = rand() % (maxValue - 1) + minValue;
- if (drop == 1) { std::cout << "* * * * *\n* *\n* # *\n* *\n* * * * *\n\n"; }
- else if (drop == 2) { std::cout << "* * * * *\n* # *\n* *\n* # *\n* * * * *\n\n"; }
- else if (drop == 3) { std::cout << "* * * * *\n* # *\n* # *\n* # *\n* * * * *\n\n"; }
- else if (drop == 4) { std::cout << "* * * * *\n* # # *\n* *\n* # # *\n* * * * *\n\n"; }
- else if (drop == 5) { std::cout << "* * * * *\n* # # *\n* # *\n* # # *\n* * * * *\n\n"; }
- else if (drop == 6) { std::cout << "* * * * *\n* # # *\n* # # *\n* # # *\n* * * * *\n\n"; }
- comp ? computerSum+= drop : playerSum += drop;
- }
- std::cout << (comp ? "My " : "You ") << "count is " << (comp ? computerSum : playerSum) << "\n\n";
- }
- if (playerSum > computerSum)
- {
- std::cout << "Congratulations!!! You are the winner!! You have " << playerSum << " while I have just " << computerSum << "\n\n";
- }
- else if (playerSum < computerSum)
- {
- std::cout << "I'm sorry =( I am the winner!! You have just " << playerSum << " while I have " << computerSum << "\n\n";
- }
- else if (playerSum == computerSum)
- {
- std::cout << "Today it's draw!! Congrats! We both have " << playerSum << "\n\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement