Delete 'Aincrad.cpp'

main
pw2aief9b 5 months ago
parent e1f9f9ee3a
commit 1ee8fb6d13

@ -1,262 +0,0 @@
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
using namespace std;
class Character {
public:
string name;
int health;
int maxHealth;
int attack;
int defense;
Character(string n, int h, int a, int d) : name(n), health(h), maxHealth(h), attack(a), defense(d) {}
bool isAlive() {
return health > 0;
}
};
class Player : public Character {
public:
int potions;
vector<string> weapons;
string currentWeapon;
int experience;
int level;
int maxExperience;
bool hasKingTreasure;
bool hasThornShield;
int baseAttack;
int weaponAttack;
Player(string n) : Character(n, 100, 5, 10), potions(0), currentWeapon("短剑"), experience(0), level(1), maxExperience(100), hasKingTreasure(false), hasThornShield(false), baseAttack(5), weaponAttack(0) {
weapons.push_back("短剑");
changeWeapon("短剑");
}
void changeWeapon(string weapon) {
if (find(weapons.begin(), weapons.end(), weapon) != weapons.end()) {
currentWeapon = weapon;
if (weapon == "短剑") {
weaponAttack = 20;
}
else if (weapon == "村好剑") {
weaponAttack = 40;
}
else if (weapon == "惠惠的爆裂魔法") {
weaponAttack = 80;
}
updateAttack();
}
}
void updateAttack() {
attack = baseAttack + weaponAttack;
}
void gainExperience(int exp) {
experience += exp;
if (experience >= maxExperience) {
experience -= maxExperience;
levelUp();
}
}
void levelUp() {
level++;
maxExperience += 100;
baseAttack++;
health = maxHealth;
defense += 1;
updateAttack();
cout << name << " 升级了!现在是等级 " << level << ",生命值完全恢复。" << endl;
}
};
class Enemy : public Character {
public:
Enemy(string n, int h, int a, int d) : Character(n, h, a, d) {}
};
void displayStatus(Character& character) {
cout << character.name << " - 生命值: " << character.health << "/" << character.maxHealth << ", 攻击力: " << character.attack << ", 防御力: " << character.defense << endl;
}
void attack(Character& attacker, Character& defender) {
int damage = attacker.attack - defender.defense;
if (damage < 0) damage = 0;
defender.health -= damage;
cout << attacker.name << " 攻击 " << defender.name << " 造成 " << damage << " 点伤害!" << endl;
if (defender.isAlive() && defender.name == "玩家" && ((Player&)defender).hasThornShield) {
attacker.health -= 10;
cout << attacker.name << " 因为荆棘护盾受到 10 点反伤!" << endl;
}
}
void usePotion(Player& player) {
if (player.potions > 0) {
player.health += 50;
if (player.health > player.maxHealth) player.health = player.maxHealth;
player.potions--;
cout << player.name << " 使用了药丸恢复了50点生命值" << endl;
}
else {
cout << "你没有药丸了!" << endl;
}
}
void battle(Player& player, Enemy& enemy, int& enemyCount, int floor) {
bool usedCurryStick = false;
while (player.isAlive() && enemy.isAlive()) {
displayStatus(player);
displayStatus(enemy);
cout << "选择你的行动: (1) 攻击 (2) 使用药丸: ";
int choice;
cin >> choice;
if (choice == 1) {
if (player.weapons.size() > 2 && player.weapons[2] == "咖喱棒" && !usedCurryStick) {
cout << "你有咖喱棒,是否使用?(1) 是 (2) 否: ";
int useCurry;
cin >> useCurry;
if (useCurry == 1) {
enemy.health = 0;
cout << player.name << " 使用咖喱棒秒杀了 " << enemy.name << "!" << endl;
usedCurryStick = true;
}
else {
attack(player, enemy);
if (enemy.isAlive()) {
attack(enemy, player);
}
}
}
else {
attack(player, enemy);
if (enemy.isAlive()) {
attack(enemy, player);
}
}
}
else if (choice == 2) {
usePotion(player);
}
if (!player.isAlive()) {
cout << player.name << " 被击败了!" << endl;
}
else if (!enemy.isAlive()) {
cout << enemy.name << " 被击败了!" << endl;
enemyCount++;
int experienceGained = (enemy.name == "大树守卫" || enemy.name == "金闪闪" || enemy.name == "宿傩") ? 200 :
(enemy.name == "精英怪物") ? 80 : 40;
player.gainExperience(experienceGained);
if (rand() % 100 < 75) {
player.potions++;
cout << "你获得了一颗药丸!" << endl;
}
if (enemyCount == 5 && find(player.weapons.begin(), player.weapons.end(), "村好剑") == player.weapons.end()) {
player.weapons.push_back("村好剑");
cout << "你获得了村好剑!" << endl;
}
if (enemyCount % 10 == 0 && find(player.weapons.begin(), player.weapons.end(), "咖喱棒") == player.weapons.end()) {
player.weapons.push_back("咖喱棒");
cout << "你获得了咖喱棒!" << endl;
}
if (rand() % 20 == 0 && find(player.weapons.begin(), player.weapons.end(), "惠惠的爆裂魔法") == player.weapons.end()) {
player.weapons.push_back("惠惠的爆裂魔法");
cout << "你获得了惠惠的爆裂魔法!" << endl;
}
if (enemy.name == "大树守卫") {
player.hasThornShield = true;
player.defense += 20;
cout << "你击败了大树守卫获得了荆棘护盾防御力加20敌人攻击时受到10点反伤" << endl;
}
if (enemy.name == "金闪闪") {
player.hasKingTreasure = true;
cout << "你击败了金闪闪,获得了技能——王的宝库!" << endl;
}
cout << "你现在有 " << player.potions << " 颗药丸。" << endl;
}
}
}
int main() {
srand(time(0));
string playerName;
cout << "请输入你的角色名字: ";
cin >> playerName;
Player player(playerName);
cout << "欢迎, " << player.name << "!" << endl;
int enemyCount = 0;
int floor = 1;
while (player.isAlive() && floor <= 100) {
Enemy enemy("哥布林", 50 + floor, 15 + floor / 2, 5 + floor / 2);
if (floor % 10 == 0 && floor != 20 && floor != 50 && floor != 100) {
enemy = Enemy("精英怪物", 100 + floor * 2, 20 + floor / 2, 15 + floor / 2);
}
if (floor == 20) {
enemy = Enemy("大树守卫", 300, 30, 20);
}
if (floor == 50) {
enemy = Enemy("金闪闪", 500, 50, 30);
}
if (floor == 100) {
enemy = Enemy("宿傩", 1000, 70, 50);
}
cout << "" << floor << " 层,你遇到了一只 " << enemy.name << "!" << endl;
battle(player, enemy, enemyCount, floor);
if (player.isAlive()) {
cout << "是否更换武器?(1) 是 (2) 否: ";
int changeWeapon;
cin >> changeWeapon;
if (changeWeapon == 1) {
cout << "你拥有的武器有: ";
for (size_t i = 0; i < player.weapons.size(); ++i) {
cout << "(" << i + 1 << ") " << player.weapons[i] << " ";
}
cout << endl;
int weaponChoice;
cin >> weaponChoice;
if (weaponChoice > 0 && weaponChoice <= player.weapons.size()) {
player.changeWeapon(player.weapons[weaponChoice - 1]);
cout << "你现在装备的是 " << player.currentWeapon << "" << endl;
}
else {
cout << "无效的选择。" << endl;
}
}
floor++;
}
}
if (player.isAlive()) {
cout << "恭喜 " << player.name << " 通关了所有楼层!" << endl;
}
else {
cout << player.name << " 在第 " << floor << " 层被击败了。" << endl;
}
return 0;
}
Loading…
Cancel
Save