#include <iostream>
#include <vector>
#include <memory>
using namespace std;
const unsigned long long python_sPrintToPrintIntOrString = numeric_limits<unsigned long long>::max();
class GameComponentFactory {
public:
vector<string> generateChoiceList() {
vector<string> temporaryContainer = {"", "石头", "剪刀", "布"};
return temporaryContainer;
}
};
class OutputManager {
private:
static void conditionalEndline(bool endlineFlag) {
if (endlineFlag) {
cout << "\n";
}
}
public:
static void displayOutput(unsigned long long numericValue, string stringValue, bool endline) {
if (numericValue != python_sPrintToPrintIntOrString) {
cout << numericValue;
} else {
cout << stringValue;
}
conditionalEndline(endline);
}
};
class InputProcessor {
public:
static unsigned long long processInputRequest(string promptText) {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, promptText, false);
unsigned long long userResponse;
cin >> userResponse;
return userResponse;
}
};
class GameRoundEvaluator {
private:
static unsigned long long computeComputerChoice(unsigned long long playerSelection) {
unsigned long long intermediateValue = (playerSelection + 2);
return (intermediateValue > 3) ? intermediateValue - 3 : intermediateValue;
}
static void announceChoices(const vector<string>& options,
unsigned long long playerChoice,
unsigned long long computerChoice) {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "电脑选择:", false);
OutputManager::displayOutput(python_sPrintToPrintIntOrString, options[computerChoice], false);
OutputManager::displayOutput(python_sPrintToPrintIntOrString, ", ", false);
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "你的选择:", false);
OutputManager::displayOutput(python_sPrintToPrintIntOrString, options[playerChoice], true);
}
public:
static bool executeRound(unsigned long long roundNumber, unsigned long long& lossCounter) {
unsigned long long playerInput = InputProcessor::processInputRequest("选择(1.石头,2.剪刀,3.布):");
if (playerInput > 3 || playerInput < 1) {
OutputManager::displayOutput(python_sPrintToPrintIntOrString,
"请输入正确的选项(1.石头,2.剪刀,3.布)", true);
return false;
}
GameComponentFactory factory;
vector<string> choiceOptions = factory.generateChoiceList();
unsigned long long computerSelection = computeComputerChoice(playerInput);
announceChoices(choiceOptions, playerInput, computerSelection);
if (playerInput > computerSelection) {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "你输了!", true);
lossCounter++;
} else if (playerInput < computerSelection) {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "你赢了!", true);
} else {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "平局!", true);
}
return true;
}
};
class GameSessionManager {
private:
unsigned long long defeatCount = 0;
unsigned long long totalRounds = 0;
void evaluateFinalOutcome() {
if (defeatCount > totalRounds / 2) {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "你输了,输了", false);
OutputManager::displayOutput(defeatCount, "", false);
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "局", false);
} else if (defeatCount < totalRounds / 2) {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "你赢了,赢了", false);
OutputManager::displayOutput(totalRounds - defeatCount, "", false);
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "局", false);
} else {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "平局!", false);
}
}
public:
void initializeGameSession() {
OutputManager::displayOutput(python_sPrintToPrintIntOrString, "欢迎来到石头剪刀布游戏!", true);
totalRounds = InputProcessor::processInputRequest("要玩几次:");
for (unsigned long long currentRound = 1; currentRound <= totalRounds; ) {
if (GameRoundEvaluator::executeRound(currentRound, defeatCount)) {
currentRound++;
}
}
evaluateFinalOutcome();
}
};
int main() {
unique_ptr<GameSessionManager> gameManager = make_unique<GameSessionManager>();
gameManager->initializeGameSession();
return 0;
}