注:请使用-std=c++11,AI生成
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
class NekoGirl {
private:
std::string name;
int energy;
int score;
std::vector<std::string> special_moves;
public:
NekoGirl(std::string n) : name(n), energy(100), score(0) {
special_moves = {"喵喵爪击", "尾巴横扫", "卖萌光波", "猫步瞬移", "罐头诱惑"};
}
bool run() {
if (energy > 0) {
int distance = rand() % 10 + 1;
score += distance;
energy -= 10;
std::cout << name << " 跑了" << distance << "米!" << std::endl;
return true;
} else {
std::cout << "喵..." << name << "没力气了!需要小鱼干!" << std::endl;
return false;
}
}
void use_special() {
int move_index = rand() % special_moves.size();
std::string move = special_moves[move_index];
int bonus = rand() % 16 + 15; // 15-30
score += bonus;
std::cout << name << " 使用了【" << move << "】!+" << bonus << "分!" << std::endl;
}
void eat_fish() {
energy = std::min(100, energy + 30);
std::cout << name << " 吃到小鱼干!能量恢复至" << energy << "!" << std::endl;
}
void steal_score(NekoGirl& other) {
int stolen = rand() % 10 + 5;
if (other.score > stolen) {
other.score -= stolen;
score += stolen;
std::cout << "" << name << " 偷走了" << other.name << "的" << stolen << "分!" << std::endl;
}
}
void display_status() const {
std::cout << " " << name << " | 能量:" << energy << " | 分数:" << score << std::endl;
}
int get_score() const { return score; }
std::string get_name() const { return name; }
int get_energy() const { return energy; }
};
class BattleSystem {
private:
NekoGirl& player1;
NekoGirl& player2;
int round;
public:
BattleSystem(NekoGirl& p1, NekoGirl& p2) : player1(p1), player2(p2), round(1) {}
void play_round() {
std::cout << "\n========== 第" << round << "回合 ==========" << std::endl;
// 玩家1行动
std::cout << "\n【" << player1.get_name() << "的回合】" << std::endl;
player1.display_status();
int action1 = rand() % 4;
execute_action(player1, player2, action1);
// 玩家2行动
std::cout << "\n【" << player2.get_name() << "的回合】" << std::endl;
player2.display_status();
int action2 = rand() % 4;
execute_action(player2, player1, action2);
round++;
}
void execute_action(NekoGirl& attacker, NekoGirl& target, int action) {
switch(action) {
case 0: // 奔跑
if (!attacker.run()) {
attacker.eat_fish();
}
break;
case 1: // 特殊技能
attacker.use_special();
break;
case 2: // 吃鱼恢复
attacker.eat_fish();
break;
case 3: // 偷分
attacker.steal_score(target);
break;
}
}
void display_battle_status() const {
std::cout << "\n====== 当前战况 ======" << std::endl;
player1.display_status();
player2.display_status();
if (player1.get_score() > player2.get_score()) {
std::cout << "领先者: " << player1.get_name() << std::endl;
} else if (player2.get_score() > player1.get_score()) {
std::cout << "领先者: " << player2.get_name() << std::endl;
} else {
std::cout << "平局!" << std::endl;
}
}
void announce_winner() const {
std::cout << "\n 游戏结束!" << std::endl;
std::cout << "最终成绩:" << std::endl;
player1.display_status();
player2.display_status();
if (player1.get_score() > player2.get_score()) {
std::cout << "\n 冠军是:" << player1.get_name() << "!" << std::endl;
std::cout << "奖励:无限量猫罐头!" << std::endl;
} else if (player2.get_score() > player1.get_score()) {
std::cout << "\n 冠军是:" << player2.get_name() << "!" << std::endl;
std::cout << "奖励:豪华猫爬架!" << std::endl;
} else {
std::cout << "\n?? 平局!两位猫娘都是赢家!" << std::endl;
std::cout << "奖励:双倍小鱼干!" << std::endl;
}
}
};
int main() {
srand(time(0)); // 随机种子
std::cout << "猫娘跑酷大对战" << std::endl;
// 创建两位猫娘
NekoGirl neko1("郑轩朗");
NekoGirl neko2("懂的都懂");
std::cout << "对战选手:" << std::endl;
neko1.display_status();
neko2.display_status();
// 创建对战系统
BattleSystem battle(neko1, neko2);
// 进行5回合对战
for (int i = 0; i < 5; i++) {
battle.play_round();
battle.display_battle_status();
// 暂停一下
std::cout << "\n按回车继续...";
std::cin.ignore();
}
// 宣布结果
battle.announce_winner();
return 0;
}