我这可是一本正经的石头剪刀布游戏!还有判断胜负平!
原版(打变量名好辛苦TAT)
#include <iostream>
using namespace std;
const unsigned long long python_sPrintToPrintIntOrString = 18446744073709551615;
string let_sPlayRock_Paper_Scissors__WhatDoYouWantToChoose_[5] = {"", "石头", "剪刀", "布"};
void print(unsigned long long doPrintInt, string doPrintString, bool doPrintEndl);
unsigned long long input(string doReturnIsInput);
int main()
{
unsigned long long playerLostTime = 0;
print(python_sPrintToPrintIntOrString, "欢迎来到石头剪刀布游戏!", 1);
unsigned long long intWhatTimeDoPlay = input("要玩几次:");
for (unsigned long long forNeedClycleNode = 1; forNeedClycleNode <= intWhatTimeDoPlay; forNeedClycleNode++)
{
unsigned long long intPlayerInput = input("选择(1.石头,2.剪刀,3.布):");
if (intPlayerInput > 3 or intPlayerInput < 1)
{
print(python_sPrintToPrintIntOrString, "请输入正确的选项(1.石头,2.剪刀,3.布)", 1);
forNeedClycleNode--;
continue;
}
unsigned long long intComputerInput = (intPlayerInput + 2);
if (intComputerInput > 3)intComputerInput -= 3;
print(python_sPrintToPrintIntOrString, "电脑选择:", 0);
print(python_sPrintToPrintIntOrString, let_sPlayRock_Paper_Scissors__WhatDoYouWantToChoose_[intComputerInput], 0);
print(python_sPrintToPrintIntOrString, ", ", 0);
print(python_sPrintToPrintIntOrString, "你的选择:", 0);
print(python_sPrintToPrintIntOrString, let_sPlayRock_Paper_Scissors__WhatDoYouWantToChoose_[intPlayerInput], 1);
if (intPlayerInput > intComputerInput || intPlayerInput == 1 && intComputerInput == 3)
{
print(python_sPrintToPrintIntOrString, "你输了!", 1);
playerLostTime++;
}
else if (intPlayerInput < intComputerInput)
{
print(python_sPrintToPrintIntOrString, "你赢了!", 1);
}
else
{
print(python_sPrintToPrintIntOrString, "平局!", 1);
}
}
if (playerLostTime > intWhatTimeDoPlay / 2)
{
print(python_sPrintToPrintIntOrString, "你输了,输了", 0);
print(playerLostTime, "", 0);
print(python_sPrintToPrintIntOrString, "局", 0);
}
else if (playerLostTime < intWhatTimeDoPlay / 2)
{
print(python_sPrintToPrintIntOrString, "你赢了,赢了", 0);
print(intWhatTimeDoPlay - playerLostTime, "", 0);
print(python_sPrintToPrintIntOrString, "局", 0);
}
else
{
print(python_sPrintToPrintIntOrString, "平局!", 0);
}
return 0;
}
//Python's input ans output
void print(unsigned long long doPrintInt, string doPrintString, bool doPrintEndl)
{
if (doPrintInt != python_sPrintToPrintIntOrString)cout << doPrintInt;
else cout << doPrintString;
if (doPrintEndl)cout << "\n";
}
unsigned long long input(string printBeforInput)
{
cout << printBeforInput;
unsigned long long doReturnIsInput;
cin >> doReturnIsInput;
return doReturnIsInput;
}
好复杂(DeePseek生成的,雀食不好运行)
#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;
}
简洁了(同为石头剪刀布游戏,为何这段如此简洁?)
#include <iostream>
using namespace std;
int main() {
int lost = 0, rounds;
string choices[] = {"", "石头", "剪刀", "布"};
cout << "欢迎来到石头剪刀布游戏!\n要玩几次:";
cin >> rounds;
for (int i = 0; i < rounds; ) {
int player;
cout << "选择(1.石头,2.剪刀,3.布):";
cin >> player;
if (player < 1 || player > 3) {
cout << "请输入正确的选项(1.石头,2.剪刀,3.布)\n";
continue;
}
int computer = (player + 1) % 3 + 1;
cout << "电脑选择:" << choices[computer] << ", 你的选择:" << choices[player] << endl;
if (player == computer % 3 + 1) lost++;
cout << (player == computer ? "平局!" : player > computer && (player != 3 || computer != 1) || (player == 1 && computer == 3) ? "你赢了!" : "你输了!") << endl;
i++;
}
cout << (lost > rounds/2 ? "你输了,输了" + to_string(lost) + "局" :
lost < rounds/2 ? "你赢了,赢了" + to_string(rounds-lost) + "局" : "平局!");
return 0;
}