#include <iostream>
#include <cstdlib>
#include <ctime>
int main() {
srand(time(0)); // 使用系统时间初始化随机数种子
std::string choices[3] = {"石头", "剪刀", "布"};
int computerChoice = rand() % 3;
int playerChoice = -1;
std::cout << "欢迎来到猜拳游戏!\n";
std::cout << "请猜拳(0-石头,1-剪刀,2-布):";
std::cin >> playerChoice;
if (playerChoice < 0 || playerChoice > 2) {
std::cout << "无效的选择!游戏结束。\n";
return 0;
}
std::cout << "你的选择是:" << choices[playerChoice] << std::endl;
std::cout << "电脑的选择是:" << choices[computerChoice] << std::endl;
if (playerChoice == computerChoice) {
std::cout << "平局!\n";
} else if ((playerChoice == 0 && computerChoice == 1) ||
(playerChoice == 1 && computerChoice == 2) ||
(playerChoice == 2 && computerChoice == 0)) {
std::cout << "恭喜,你赢了!\n";
} else {
std::cout << "很遗憾,你输了!\n";
}
return 0;
}
动动手指,点个赞吧。