下面是一个简单的金木水火土五行克制游戏的C++代码示例。在这个游戏中,玩家需要选择一个五行,然后根据选择的五行来攻击或防御其他五行。
#include <iostream>
#include <string>
int main() {
std::string playerChoice;
std::string computerChoice;
std::string result;
std::cout << "请选择你的五行(金木水火土):";
std::cin >> playerChoice;
// 计算机随机选择一个五行
std::string possibleChoices[] = {"金", "木", "水", "火", "土"};
int randomIndex = rand() % 5;
computerChoice = possibleChoices[randomIndex];
// 根据五行相生相克关系判断胜负
if (playerChoice == "金") {
if (computerChoice == "木") {
result = "你赢了!金克木。";
} else if (computerChoice == "水") {
result = "平局!金生水。";
} else if (computerChoice == "火