剪刀石头布代码

360影视 2025-01-18 23:12 1

摘要:#include #include #include #include #include // Windows系统需要这个头文件来设置控制台编码using namesp

#include #include #include #include #include // Windows系统需要这个头文件来设置控制台编码using namespace std;class RockPaperScissors {private:int playerScore;int computerScore;int rounds;string getComputerChoice {int choice = rand % 3;switch (choice) {case 0: return "rock";case 1: return "scissors";case 2: return "paper";default: return "rock";}}string getChineseChoice(const string& choice) {if (choice == "rock") return "石头";if (choice == "scissors") return "剪刀";if (choice == "paper") return "布";return "";}bool determineWinner(const string& playerChoice, const string& computerChoice) {if (playerChoice == computerChoice) {cout 0) {string playerInput;cout > playerInput;if (!isValidChoice(playerInput)) {cout computerScore) {cout > playAgain;if (playAgain == 'y' || playAgain == 'Y') {game.resetGame;cout

来源:生活小乐趣

相关推荐