寻1(后面的代码搜寻2)
2025-09-03 20:59:48
发布于:广东
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <limits>
using namespace std;
// 清屏函数,兼容不同操作系统
void clearScreen() {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
// 修为境界定义
enum Realm {
MORTAL, // 凡人
FOUNDATION, // 筑基
GOLDEN, // 金丹
SOUL, // 元婴
TRANSFORMATION,// 化神
ASCENSION // 飞升
};
// 物品类型
enum ItemType {
CONSUMABLE, // 消耗品
EQUIPMENT, // 装备
MATERIAL // 材料
};
// 技能类型
enum SkillType {
ATTACK, // 攻击技能
DEFENSE, // 防御/增益技能
HEAL // 治疗技能
};
// int转string函数,兼容旧编译器
string intToString(int num) {
stringstream ss;
ss << num;
return ss.str();
}
// 技能类声明
class Skill {
private:
string name;
string description;
SkillType type;
int cost; // 灵力消耗
int power; // 技能威力/效果值
int cooldown; // 冷却时间(回合)
int currentCooldown; // 当前剩余冷却
public:
Skill(string n, string d, SkillType t, int c, int p, int cd)
: name(n), description(d), type(t), cost(c), power(p),
cooldown(cd), currentCooldown(0) {}
// 用于加载存档的构造函数
Skill(ifstream& saveFile);
// 使用技能
bool use(class Cultivator& user, class Monster* target = NULL);
// 每回合结束时减少冷却
void reduceCooldown() {
if (currentCooldown > 0) {
currentCooldown--;
}
}
// 存档函数
void save(ofstream& saveFile) const;
// 获取技能信息
string getName() const { return name; }
string getDescription() const { return description; }
SkillType getType() const { return type; }
int getCost() const { return cost; }
int getPower() const { return power; }
bool isAvailable() const { return currentCooldown == 0; }
string getCooldownStatus() const {
return currentCooldown > 0 ? "(" + intToString(currentCooldown) + "回合冷却)" : "";
}
};
// 物品基类
class Item {
protected:
string name;
string description;
ItemType type;
int value; // 物品价值(用于交易)
public:
Item(string n, string d, ItemType t, int v)
: name(n), description(d), type(t), value(v) {}
// 用于加载存档的构造函数
Item(ifstream& saveFile);
virtual ~Item() {}
virtual void use(class Cultivator& user) = 0;
// 纯虚函数,用于存档
virtual void save(ofstream& saveFile) const = 0;
// 纯虚函数,用于识别物品类型
virtual string getTypeIdentifier() const = 0;
string getName() const { return name; }
string getDescription() const { return description; }
ItemType getType() const { return type; }
int getValue() const { return value; }
virtual string getEffectDescription() const = 0;
};
// 消耗品(丹药等)
class Consumable : public Item {
private:
int cultivationGain; // 增加修为
int healthGain; // 恢复生命
int spiritGain; // 恢复灵力
public:
Consumable(string n, string d, int v, int cg, int hg, int sg = 0)
: Item(n, d, CONSUMABLE, v), cultivationGain(cg), healthGain(hg), spiritGain(sg) {}
// 用于加载存档的构造函数
Consumable(ifstream& saveFile);
void use(class Cultivator& user);
string getEffectDescription() const {
string desc = "修为+" + intToString(cultivationGain) + ",生命+" + intToString(healthGain);
if (spiritGain > 0) {
desc += ",灵力+" + intToString(spiritGain);
}
return desc;
}
void save(ofstream& saveFile) const;
string getTypeIdentifier() const { return "CONSUMABLE"; }
};
// 装备
class Equipment : public Item {
private:
int attackBonus; // 攻击加成
int defenseBonus; // 防御加成
int spiritBonus; // 灵力加成
bool isEquipped; // 是否装备
public:
Equipment(string n, string d, int v, int ab, int db, int sb = 0)
: Item(n, d, EQUIPMENT, v), attackBonus(ab), defenseBonus(db),
spiritBonus(sb), isEquipped(false) {}
// 用于加载存档的构造函数
Equipment(ifstream& saveFile);
void use(class Cultivator& user);
string getEffectDescription() const {
return "攻击+" + intToString(attackBonus) + ",防御+" + intToString(defenseBonus) +
",灵力+" + intToString(spiritBonus);
}
int getAttackBonus() const { return attackBonus; }
int getDefenseBonus() const { return defenseBonus; }
int getSpiritBonus() const { return spiritBonus; }
bool equipped() const { return isEquipped; }
void setEquipped(bool status) { isEquipped = status; }
void save(ofstream& saveFile) const;
string getTypeIdentifier() const { return "EQUIPMENT"; }
};
// 材料(用于突破、交易等)
class Material : public Item {
private:
int breakthroughBonus; // 提升突破成功率
public:
Material(string n, string d, int v, int bb)
: Item(n, d, MATERIAL, v), breakthroughBonus(bb) {}
// 用于加载存档的构造函数
Material(ifstream& saveFile);
void use(class Cultivator& user);
string getEffectDescription() const {
return "突破成功率+" + intToString(breakthroughBonus) + "%";
}
int getBreakthroughBonus() const { return breakthroughBonus; }
void save(ofstream& saveFile) const;
string getTypeIdentifier() const { return "MATERIAL"; }
};
// 门派
class Sect {
private:
string name;
string description;
int contribution; // 门派贡献度
public:
Sect(string n, string d) : name(n), description(d), contribution(0) {}
// 用于加载存档的构造函数
Sect(ifstream& saveFile);
void addContribution(int amount) { contribution += amount; }
int getContribution() const { return contribution; }
string getName() const { return name; }
string getDescription() const { return description; }
// 存档函数
void save(ofstream& saveFile) const;
// 门派任务
struct Task {
string description;
int contributionReward;
int difficulty; // 1-10
Task(string d, int cr, int diff)
: description(d), contributionReward(cr), difficulty(diff) {}
};
// 获取随机门派任务
Task getRandomTask() const {
vector<Task> tasks;
tasks.push_back(Task("采集10株灵草", 20, 3));
tasks.push_back(Task("清理门派周边妖兽", 50, 5));
tasks.push_back(Task("护送门派弟子下山", 30, 4));
tasks.push_back(Task("看守藏经阁一月", 40, 2));
tasks.push_back(Task("参加门派大比", 100, 8));
return tasks[rand() % tasks.size()];
}
};
// 怪物结构
struct Monster {
string name;
string title; // 怪物称号,增加多样性
int health;
int maxHealth;
int attack;
int defense;
int dodgeRate;
int realmLevel; // 对应玩家境界等级
Item* drop;
int expReward; // 击杀经验/修为奖励
Monster(string n, string t, int h, int a, int d, int dr, int rl, Item* dp, int exp)
: name(n), title(t), health(h), maxHealth(h), attack(a), defense(d),
dodgeRate(dr), realmLevel(rl), drop(dp), expReward(exp) {}
~Monster() {
delete drop;
}
// 尝试闪避
bool tryDodge() const {
return rand() % 100 < dodgeRate;
}
// 受到伤害
void takeDamage(int damage) {
int reducedDamage = max(1, damage - defense / 3);
health = max(0, health - reducedDamage);
cout << name << title << "受到" << reducedDamage << "点伤害!\n";
}
// 怪物行动选择
void takeAction(class Cultivator& player);
// 获取完整名称(名字+称号)
string getFullName() const {
return name + title;
}
};
// 角色类
class Cultivator {
private:
string name;
Realm realm;
int cultivation; // 当前修为值
int maxCultivation; // 当前境界最大修为
int health;
int maxHealth;
int attack;
int defense;
int spirit; // 灵力(用于释放技能)
int maxSpirit; // 最大灵力
int dodgeRate; // 闪避率(百分比)
vector<Item*> inventory;
int inventoryCapacity; // 背包容量
vector<Skill*> skills; // 技能列表
vector<string> realmNames;
Sect* sect; // 所属门派
int reputation; // 声望
int turnBuff; // 回合增益(如防御提升)
public:
// 构造函数
Cultivator(string n);
// 用于加载存档的构造函数
Cultivator(ifstream& saveFile);
~Cultivator();
// 存档和读档函数
bool save(const string& filename) const;
bool load(const string& filename);
// 学习新技能
void learnSkill(Skill* skill) {
skills.push_back(skill);
cout << "学会新技能:" << skill->getName() << "\n";
}
// 修炼函数
void cultivate();
// 突破境界
bool breakthrough(int materialBonus = 0);
// 探索函数
bool explore();
// 战斗函数
bool fight(Monster& monster);
// 显示状态
void showStatus();
// 加入门派
void joinSect();
// 门派任务
void doSectTask();
// 获取名称
string getName() const { return name; }
// 检查是否已经飞升
bool hasAscended() const { return realm == ASCENSION; }
// 使用物品
void useItem();
// 丢弃物品
void discardItem();
// 尝试闪避
bool tryDodge() const {
return rand() % 100 < dodgeRate;
}
// 受到伤害
void takeDamage(int damage);
// 恢复生命
void heal(int amount) {
health = min(health + amount, maxHealth);
cout << name << "恢复了" << amount << "点生命!\n";
}
// 恢复灵力
void restoreSpirit(int amount) {
spirit = min(spirit + amount, maxSpirit);
cout << name << "恢复了" << amount << "点灵力!\n";
}
// 消耗灵力
bool consumeSpirit(int amount) {
if (spirit >= amount) {
spirit -= amount;
return true;
}
cout << "灵力不足,无法释放技能!\n";
return false;
}
// 背包是否已满
bool isInventoryFull() const {
return inventory.size() >= (size_t)inventoryCapacity;
}
// 添加物品
bool addItem(Item* item) {
if (isInventoryFull()) {
cout << "背包已满,无法拾取" << item->getName() << "!\n";
delete item;
return false;
}
inventory.push_back(item);
cout << "获得 " << item->getName() << "!\n";
return true;
}
// 获取技能列表
vector<Skill*>& getSkills() { return skills; }
// 回合结束时的处理(如冷却减少、增益消失等)
void endTurn();
// 设置回合增益
void setTurnBuff(int value) {
turnBuff = value;
cout << name << "获得了" << value << "点临时加成!\n";
}
// 获取当前境界
Realm getRealm() const { return realm; }
int getAttack() const {
// 攻击时考虑临时增益
return attack + (turnBuff > 0 ? turnBuff : 0);
}
int getHealth() const { return health; }
void setHealth(int h) { health = h; }
int getMaxHealth() const { return maxHealth; }
int getSpirit() const { return spirit; }
int getMaxSpirit() const { return maxSpirit; }
int getDefense() const { return defense; }
int getDodgeRate() const { return dodgeRate; }
};
// 门派菜单函数声明
void showSectMenu(Cultivator& player);
// 根据玩家属性生成稍强的怪物
Monster* generateChallengingMonster(const Cultivator& player) {
// 基于玩家属性生成稍强的怪物
int playerRealm = (int)player.getRealm();
int monsterRealm = min(playerRealm + 1, 4); // 怪物境界比玩家高1级或同等级,最高化神境
// 怪物属性基于玩家属性,但稍强一些(10-30%)
float healthMultiplier = 1.2f + (rand() % 30) / 100.0f; // 1.2-1.5倍
float attackMultiplier = 1.1f + (rand() % 20) / 100.0f; // 1.1-1.3倍
float defenseMultiplier = 0.9f + (rand() % 10) / 100.0f; // 0.9-1.0倍
float dodgeMultiplier = 0.9f + (rand() % 20) / 100.0f; // 0.9-1.1倍
int monsterHealth = (int)(player.getMaxHealth() * healthMultiplier);
int monsterAttack = (int)(player.getAttack() * attackMultiplier);
int monsterDefense = (int)(player.getDefense() * defenseMultiplier);
int monsterDodge = (int)(player.getDodgeRate() * dodgeMultiplier);
// 确保怪物属性不会过低
monsterHealth = max(monsterHealth, 30);
monsterAttack = max(monsterAttack, 5);
monsterDefense = max(monsterDefense, 2);
monsterDodge = max(monsterDodge, 3);
// 怪物名称和称号组合 - 修复初始化方式以兼容C++98
vector<pair<string, string> > monsterTypes;
monsterTypes.push_back(pair<string, string>("野", "犬妖"));
monsterTypes.push_back(pair<string, string>("猛", "虎精"));
monsterTypes.push_back(pair<string, string>("妖", "狐女"));
monsterTypes.push_back(pair<string, string>("恶", "灵体"));
monsterTypes.push_back(pair<string, string>("魔", "妖兽"));
monsterTypes.push_back(pair<string, string>("血", "蝙蝠"));
monsterTypes.push_back(pair<string, string>("石", "巨人"));
monsterTypes.push_back(pair<string, string>("骨", "战士"));
monsterTypes.push_back(pair<string, string>("幽", "灵鬼"));
monsterTypes.push_back(pair<string, string>("火", "麒麟"));
// 根据境界选择更适合的怪物类型
int typeIndex;
if (playerRealm <= 1) {
typeIndex = rand() % 3; // 低级怪物
} else if (playerRealm <= 3) {
typeIndex = 3 + rand() % 3; // 中级怪物
} else {
typeIndex = 6 + rand() % 4; // 高级怪物
}
const pair<string, string>& monsterType = monsterTypes[typeIndex];
// 根据怪物强度调整奖励
int expReward = 50 + monsterRealm * 50;
Item* drop = NULL; // 用NULL代替nullptr以兼容C++98
// 根据怪物境界生成掉落物
if (rand() % 3 != 0) { // 70%概率掉落物品
if (rand() % 2 == 0) {
// 材料
int bonus = 5 + monsterRealm * 5;
drop = new Material(
(monsterType.first + monsterType.second + "之核"),
"蕴含" + monsterType.first + monsterType.second + "力量的核心",
30 + monsterRealm * 20,
bonus
);
} else if (rand() % 3 == 0) {
// 装备
int attackBonus = 5 + monsterRealm * 5;
int defenseBonus = 3 + monsterRealm * 3;
drop = new Equipment(
(monsterType.first + monsterType.second + "之爪"),
"用" + monsterType.first + monsterType.second + "躯体部分制成的装备",
50 + monsterRealm * 30,
attackBonus,
defenseBonus
);
} else {
// 消耗品
int healthGain = 20 + monsterRealm * 30;
int spiritGain = 10 + monsterRealm * 15;
drop = new Consumable(
(monsterType.first + "元丹"),
"提炼自" + monsterType.first + monsterType.second + "的内丹",
40 + monsterRealm * 25,
20 + monsterRealm * 30,
healthGain,
spiritGain
);
}
}
return new Monster(
monsterType.first,
monsterType.second,
monsterHealth,
monsterAttack,
monsterDefense,
monsterDodge,
monsterRealm,
drop,
expReward
);
}
// 技能类方法实现
Skill::Skill(ifstream& saveFile) {
getline(saveFile, name);
getline(saveFile, description);
int t;
saveFile >> t;
type = (SkillType)t;
saveFile >> cost >> power >> cooldown >> currentCooldown;
// 读取换行符
string dummy;
getline(saveFile, dummy);
}
void Skill::save(ofstream& saveFile) const {
saveFile << name << endl;
saveFile << description << endl;
saveFile << type << endl;
saveFile << cost << endl;
saveFile << power << endl;
saveFile << cooldown << endl;
saveFile << currentCooldown << endl;
}
bool Skill::use(Cultivator& user, Monster* target) {
// 检查灵力是否足够
if (!user.consumeSpirit(cost)) {
return false;
}
cout << user.getName() << "使用了" << name << "!\n";
// 根据技能类型执行不同效果
switch (type) {
case ATTACK:
if (target) {
if (target->tryDodge()) {
cout << target->getFullName() << "避开了" << name << "!\n";
} else {
// 计算技能伤害(基于玩家攻击和技能威力)
int damage = user.getAttack() + power;
target->takeDamage(damage);
}
}
break;
case DEFENSE:
user.setTurnBuff(power);
break;
case HEAL:
if (power > 0) {
user.heal(power);
} else {
user.restoreSpirit(-power); // 用负值表示恢复灵力
}
break;
}
// 设置冷却
currentCooldown = cooldown;
return true;
}
// 物品类方法实现
Item::Item(ifstream& saveFile) {
getline(saveFile, name);
getline(saveFile, description);
int t;
saveFile >> t;
type = (ItemType)t;
saveFile >> value;
// 读取换行符
string dummy;
getline(saveFile, dummy);
}
// 消耗品类方法实现
Consumable::Consumable(ifstream& saveFile) : Item(saveFile) {
saveFile >> cultivationGain >> healthGain >> spiritGain;
// 读取换行符
string dummy;
getline(saveFile, dummy);
}
void Consumable::use(Cultivator& user) {
cout << user.getName() << "使用了" << name << "!\n";
user.setHealth(min(user.getHealth() + healthGain, user.getMaxHealth()));
user.restoreSpirit(spiritGain);
// 修为增加
}
void Consumable::save(ofstream& saveFile) const {
saveFile << name << endl;
saveFile << description << endl;
saveFile << type << endl;
saveFile << value << endl;
saveFile << cultivationGain << endl;
saveFile << healthGain << endl;
saveFile << spiritGain << endl;
}
// 装备类方法实现
Equipment::Equipment(ifstream& saveFile) : Item(saveFile) {
saveFile >> attackBonus >> defenseBonus >> spiritBonus >> isEquipped;
// 读取换行符
string dummy;
getline(saveFile, dummy);
}
void Equipment::use(Cultivator& user) {
if (isEquipped) {
cout << user.getName() << "卸下了" << name << "!\n";
isEquipped = false;
} else {
cout << user.getName() << "装备了" << name << "!\n";
isEquipped = true;
}
}
void Equipment::save(ofstream& saveFile) const {
saveFile << name << endl;
saveFile << description << endl;
saveFile << type << endl;
saveFile << value << endl;
saveFile << attackBonus << endl;
saveFile << defenseBonus << endl;
saveFile << spiritBonus << endl;
saveFile << isEquipped << endl;
}
// 材料类方法实现
Material::Material(ifstream& saveFile) : Item(saveFile) {
saveFile >> breakthroughBonus;
// 读取换行符
string dummy;
getline(saveFile, dummy);
}
void Material::use(Cultivator& user) {
cout << user.getName() << "使用" << name << "辅助突破!\n";
user.breakthrough(breakthroughBonus);
}
void Material::save(ofstream& saveFile) const {
saveFile << name << endl;
saveFile << description << endl;
saveFile << type << endl;
saveFile << value << endl;
saveFile << breakthroughBonus << endl;
}
// 门派类方法实现
Sect::Sect(ifstream& saveFile) {
getline(saveFile, name);
getline(saveFile, description);
saveFile >> contribution;
// 读取换行符
string dummy;
getline(saveFile, dummy);
}
void Sect::save(ofstream& saveFile) const {
saveFile << name << endl;
saveFile << description << endl;
saveFile << contribution << endl;
}
// 角色类方法实现
Cultivator::Cultivator(string n) {
name = n;
realm = MORTAL;
cultivation = 0;
maxCultivation = 100;
maxHealth = 100;
health = maxHealth;
attack = 10;
defense = 5;
maxSpirit = 50;
spirit = maxSpirit;
dodgeRate = 5;
inventoryCapacity = 10;
sect = NULL;
reputation = 0;
turnBuff = 0;
// 初始化境界名称
realmNames.push_back("凡人");
realmNames.push_back("筑基");
realmNames.push_back("金丹");
realmNames.push_back("元婴");
realmNames.push_back("化神");
realmNames.push_back("飞升");
// 初始技能
learnSkill(new Skill("基础剑击", "基础的剑击攻击", ATTACK, 5, 15, 0));
learnSkill(new Skill("凝神防御", "提升自身防御1回合", DEFENSE, 8, 20, 2));
}
Cultivator::Cultivator(ifstream& saveFile) {
// 读取基本属性
getline(saveFile, name);
int r;
saveFile >> r;
realm = (Realm)r;
saveFile >> cultivation >> maxCultivation;
saveFile >> health >> maxHealth;
saveFile >> attack >> defense;
saveFile >> spirit >> maxSpirit;
saveFile >> dodgeRate >> inventoryCapacity;
saveFile >> reputation >> turnBuff;
// 读取换行符
string dummy;
getline(saveFile, dummy);
// 初始化境界名称
realmNames.push_back("凡人");
realmNames.push_back("筑基");
realmNames.push_back("金丹");
realmNames.push_back("元婴");
realmNames.push_back("化神");
realmNames.push_back("飞升");
// 读取门派信息
bool hasSect;
saveFile >> hasSect;
getline(saveFile, dummy); // 读取换行符
if (hasSect) {
sect = new Sect(saveFile);
} else {
sect = NULL;
}
// 读取技能
int skillCount;
saveFile >> skillCount;
getline(saveFile, dummy); // 读取换行符
for (int i = 0; i < skillCount; i++) {
skills.push_back(new Skill(saveFile));
}
// 读取物品
int itemCount;
saveFile >> itemCount;
getline(saveFile, dummy); // 读取换行符
for (int i = 0; i < itemCount; i++) {
string typeId;
getline(saveFile, typeId);
if (typeId == "CONSUMABLE") {
inventory.push_back(new Consumable(saveFile));
} else if (typeId == "EQUIPMENT") {
inventory.push_back(new Equipment(saveFile));
} else if (typeId == "MATERIAL") {
inventory.push_back(new Material(saveFile));
}
}
}
Cultivator::~Cultivator() {
// 清理物品内存
for (size_t i = 0; i < inventory.size(); ++i) {
delete inventory[i];
}
// 清理技能内存
for (size_t i = 0; i < skills.size(); ++i) {
delete skills[i];
}
delete sect;
}
bool Cultivator::save(const string& filename) const {
ofstream saveFile(filename.c_str());
if (!saveFile.is_open()) {
return false;
}
// 保存基本属性
saveFile << name << endl;
saveFile << realm << endl;
saveFile << cultivation << endl << maxCultivation << endl;
saveFile << health << endl << maxHealth << endl;
saveFile << attack << endl << defense << endl;
saveFile << spirit << endl << maxSpirit << endl;
saveFile << dodgeRate << endl << inventoryCapacity << endl;
saveFile << reputation << endl << turnBuff << endl;
// 保存门派信息
if (sect) {
saveFile << "1" << endl; // 表示有门派
sect->save(saveFile);
} else {
saveFile << "0" << endl; // 表示没有门派
}
// 保存技能
saveFile << skills.size() << endl;
for (size_t i = 0; i < skills.size(); ++i) {
skills[i]->save(saveFile);
}
// 保存物品
saveFile << inventory.size() << endl;
for (size_t i = 0; i < inventory.size(); ++i) {
saveFile << inventory[i]->getTypeIdentifier() << endl;
inventory[i]->save(saveFile);
}
saveFile.close();
return true;
}
bool Cultivator::load(const string& filename) {
// 清除现有数据
for (size_t i = 0; i < inventory.size(); ++i) {
delete inventory[i];
}
inventory.clear();
for (size_t i = 0; i < skills.size(); ++i) {
delete skills[i];
}
skills.clear();
delete sect;
sect = NULL;
// 读取存档文件
ifstream saveFile(filename.c_str());
if (!saveFile.is_open()) {
return false;
}
// 读取基本属性
getline(saveFile, name);
int r;
saveFile >> r;
realm = (Realm)r;
saveFile >> cultivation >> maxCultivation;
saveFile >> health >> maxHealth;
saveFile >> attack >> defense;
saveFile >> spirit >> maxSpirit;
saveFile >> dodgeRate >> inventoryCapacity;
saveFile >> reputation >> turnBuff;
// 读取换行符
string dummy;
getline(saveFile, dummy);
// 读取门派信息
bool hasSect;
saveFile >> hasSect;
getline(saveFile, dummy); // 读取换行符
if (hasSect) {
sect = new Sect(saveFile);
} else {
sect = NULL;
}
// 读取技能
int skillCount;
saveFile >> skillCount;
getline(saveFile, dummy); // 读取换行符
for (int i = 0; i < skillCount; i++) {
skills.push_back(new Skill(saveFile));
}
// 读取物品
int itemCount;
saveFile >> itemCount;
getline(saveFile, dummy); // 读取换行符
for (int i = 0; i < itemCount; i++) {
string typeId;
getline(saveFile, typeId);
if (typeId == "CONSUMABLE") {
inventory.push_back(new Consumable(saveFile));
} else if (typeId == "EQUIPMENT") {
inventory.push_back(new Equipment(saveFile));
} else if (typeId == "MATERIAL") {
inventory.push_back(new Material(saveFile));
}
}
saveFile.close();
return true;
}
void Cultivator::cultivate() {
// 基础修炼收益
int baseGain = rand() % 20 + 5;
// 根据境界提升修炼效率
float realmBonus = 1.0f + (int)realm * 0.2f;
// 门派加成
float sectBonus = sect ? 1.2f : 1.0f;
int totalGain = (int)(baseGain * realmBonus * sectBonus);
cultivation += totalGain;
// 修炼也会恢复灵力
int spiritGain = rand() % 10 + 5;
spirit = min(spirit + spiritGain, maxSpirit);
clearScreen();
cout << "\n" << name << "潜心修炼,获得 " << totalGain << " 点修为!\n";
cout << "同时恢复了 " << spiritGain << " 点灵力!\n";
// 检查是否突破境界
if (cultivation >= maxCultivation) {
cout << "修为已达当前境界上限,可尝试突破!\n";
}
system("pause");
}
bool Cultivator::breakthrough(int materialBonus) {
if (realm == ASCENSION) return false;
if (cultivation < maxCultivation) {
cout << "修为不足,无法突破!\n";
return false;
}
clearScreen();
cout << "\n【尝试突破" << realmNames[realm + 1] << "境...】\n";
// 基础成功率随境界降低
int baseChance = 80 - (int)realm * 10;
// 加入材料加成
int successChance = baseChance + materialBonus;
successChance = min(successChance, 95); // 最高95%成功率
cout << "突破成功率:" << successChance << "%\n";
这里空空如也
有帮助,赞一个