deepseek写的猫武士爪机源代码
deepseek写的,不保证质量很高,可能有谬误,但是应该不会对电脑产生不良影响。
#include <iostream>
#include <string>
#include <map>
#include <cstdlib>
#include <ctime>
#include <limits>
using namespace std;
// 密码验证函数
bool authenticate() {
string password;
int attempts = 3;
cout << "欢迎来到猫武士爪机模拟器" << endl;
cout << "-----------------------" << endl;
while (attempts > 0) {
cout << "请输入密码 (剩余尝试次数: " << attempts << "): ";
cin >> password;
if (password == "WarriorCats") {
cout << "密码正确!欢迎使用爪机。" << endl;
return true;
} else {
cout << "密码错误!" << endl;
attempts--;
}
}
cout << "尝试次数过多,爪机已锁定。" << endl;
return false;
}
// 显示帮助信息
void showHelp() {
cout << "\n可用命令:" << endl;
cout << "help - 显示帮助信息" << endl;
cout << "query [角色名] - 查询猫武士角色信息" << endl;
cout << "game - 玩捕猎小游戏" << endl;
cout << "exit - 退出爪机" << endl;
cout << "\n可查询的角色: Firestar, Graystripe, Bluestar, Tigerstar, Scourge" << endl;
}
// 初始化角色数据库
map<string, string> initializeCharacterDatabase() {
map<string, string> characters;
characters["Firestar"] =
"火星(Firestar):\n"
"原名拉斯特(Rusty),宠物猫出身,后加入雷族。\n"
"成为雷族族长后领导族群度过许多危机。\n"
"伴侣是沙风(Sandstorm),女儿是叶池(Leafpool)和松鼠飞(Squirrelflight)。\n"
"以勇气、忠诚和智慧闻名。";
characters["Graystripe"] =
"灰条(Graystripe):\n"
"火星最好的朋友,雷族副族长。\n"
"曾与河族的银溪(Silverstream)相爱并育有子女。\n"
"因救火星而被两脚兽抓走,后回到族群。\n"
"以力量和忠诚著称。";
characters["Bluestar"] =
"蓝星(Bluestar):\n"
"雷族前族长,火星的导师。\n"
"曾是一位伟大的领导者,但后期因失去信任而精神崩溃。\n"
"为了救火星而牺牲自己。\n"
"以智慧和远见闻名。";
characters["Tigerstar"] =
"虎星(Tigerstar):\n"
"野心勃勃的影族族长,曾是雷族副族长。\n"
"试图通过武力统一森林里的所有族群。\n"
"被长鞭(Scourge)杀死。\n"
"以力量和残酷闻名。";
characters["Scourge"] =
"长鞭(Scourge):\n"
"血族首领,体型小但极其危险。\n"
"曾是一只宠物猫,因被虎星欺负而怀恨在心。\n"
"在战斗中杀死了虎星。\n"
"以冷酷无情著称。";
return characters;
}
// 查询角色信息
void queryCharacter(const string& name, const map<string, string>& characters) {
auto it = characters.find(name);
if (it != characters.end()) {
cout << "\n" << it->second << endl;
} else {
cout << "未找到角色: " << name << endl;
cout << "可查询的角色有: Firestar, Graystripe, Bluestar, Tigerstar, Scourge" << endl;
}
}
// 捕猎小游戏
void playHuntingGame() {
cout << "\n=== 捕猎小游戏 ===" << endl;
cout << "你是一只猫武士,需要在森林中捕猎为族群带回食物。" << endl;
cout << "你将遇到不同的猎物,选择正确的捕猎方式才能成功。" << endl;
srand(time(0));
int score = 0;
int rounds = 3;
for (int i = 1; i <= rounds; i++) {
cout << "\n第 " << i << " 轮捕猎:" << endl;
int preyType = rand() % 3;
int correctChoice = rand() % 3 + 1;
switch (preyType) {
case 0:
cout << "你发现了一只老鼠正在吃种子。" << endl;
break;
case 1:
cout << "你看到一只麻雀在低矮的树枝上。" << endl;
break;
case 2:
cout << "一只兔子正在空地吃草。" << endl;
break;
}
cout << "选择你的捕猎方式:" << endl;
cout << "1. 伏击 (悄悄接近然后突袭)" << endl;
cout << "2. 追逐 (快速追赶猎物)" << endl;
cout << "3. 等待 (保持不动等待最佳时机)" << endl;
int choice;
cout << "你的选择 (1-3): ";
cin >> choice;
if (choice == correctChoice) {
cout << "成功!你捕获了猎物!" << endl;
score++;
} else {
cout << "哦不!猎物逃走了。" << endl;
cout << "正确的捕猎方式应该是: " << correctChoice << endl;
}
}
cout << "\n游戏结束!你的得分: " << score << "/" << rounds << endl;
if (score == rounds) {
cout << "太棒了!你是一名出色的猎手!" << endl;
} else if (score > 0) {
cout << "不错的表现,继续练习会更好!" << endl;
} else {
cout << "也许你该向长老请教捕猎技巧。" << endl;
}
}
int main() {
if (!authenticate()) {
return 0;
}
map<string, string> characters = initializeCharacterDatabase();
string command;
showHelp();
while (true) {
cout << "\n爪机 > ";
cin >> command;
if (command == "exit") {
cout << "再见!愿星族照亮你的前路。" << endl;
break;
} else if (command == "help") {
showHelp();
} else if (command == "query") {
string name;
cin >> name;
queryCharacter(name, characters);
} else if (command == "game") {
playHuntingGame();
} else {
cout << "未知命令。输入 'help' 查看可用命令。" << endl;
// 清除输入缓冲区
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
}
return 0;
}