龙腾4.6
2026-08-09 12:58:15
发布于:浙江
//重大升级
//增加灵力系统
//优化角色机制
//增加PVE和PVP
//优化攻击描写
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <windows.h>
#include <string>
#include <vector>
using namespace std;
int hp,attack,defense,mpRate;
struct Hero
{
string name;
int hp;
int maxHp;
int mp;
int maxMp;
int attack;
int defense;
bool shield;
int shieldValue;
int stunTurn; // 眩晕剩余回合,0=无眩晕
double critRate;
};
Hero createHero (int id)
{
Hero h;
switch (id)
{
case 1: // 鲤逍遥
h.name = "鲤逍遥"; h.maxHp=1400hp; h.hp=h.maxHp;
h.maxMp=1800mpRate; h.mp=h.maxMp;
h.attack=230attack; h.defense=65defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.25; break;
case 2: // 鹊瑶
h.name = "鹊瑶"; h.maxHp=1150hp; h.hp=h.maxHp;
h.maxMp=2080mpRate; h.mp=h.maxMp;
h.attack=270attack; h.defense=45defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.30; break;
case 3: // 鹰乘风
h.name = "鹰乘风"; h.maxHp=1250hp; h.hp=h.maxHp;
h.maxMp=1600mpRate; h.mp=h.maxMp;
h.attack=250attack; h.defense=55defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.22; break;
case 4: // 熊莫开
h.name = "熊莫开"; h.maxHp=1900hp; h.hp=h.maxHp;
h.maxMp=1400mpRate; h.mp=h.maxMp;
h.attack=180attack; h.defense=110defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.12; break;
case 5: // 蛮神爪牙
h.name = "蛮神爪牙"; h.maxHp=1500hp; h.hp=h.maxHp;
h.maxMp=1520mpRate; h.mp=h.maxMp;
h.attack=240attack; h.defense=50defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.18; break;
case 6: // 梅寒衣
h.name = "梅寒衣"; h.maxHp=1300hp; h.hp=h.maxHp;
h.maxMp=1760mpRate; h.mp=h.maxMp;
h.attack=260attack; h.defense=60defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.24; break;
case 7: // 兔暗香
h.name = "兔暗香"; h.maxHp=1050hp; h.hp=h.maxHp;
h.maxMp=1680mpRate; h.mp=h.maxMp;
h.attack=280attack; h.defense=40defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.32; break;
case 8: // 鲤余欢
h.name = "鲤余欢"; h.maxHp=1350hp; h.hp=h.maxHp;
h.maxMp=1840mpRate; h.mp=h.maxMp;
h.attack=240attack; h.defense=70defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.23; break;
case 9: // 剑无忌
h.name = "剑无忌"; h.maxHp=1200hp; h.hp=h.maxHp;
h.maxMp=1720mpRate; h.mp=h.maxMp;
h.attack=270attack; h.defense=55defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.26; break;
case 10: // 蛮神使者
h.name = "蛮神使者"; h.maxHp=1600hp; h.hp=h.maxHp;
h.maxMp=1640mpRate; h.mp=h.maxMp;
h.attack=250attack; h.defense=60defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.20; break;
default:
h.name = "蛮神爪牙"; h.maxHp=1500hp; h.hp=h.maxHp;
h.maxMp=1520mpRate; h.mp=h.maxMp;
h.attack=240attack; h.defense=50defense;
h.shield=0; h.shieldValue=0; h.stunTurn=0; h.critRate=0.18; break;
}
return h;
}
void showStatus (Hero a, Hero b)
{
cout << "----------------------------------------------------" << endl;
cout << left << setw (12) << a.name
<< "HP:" << setw (5) << a.hp << "/" << a.maxHp
<< " MP:" << setw (4) << a.mp << "/" << a.maxMp;
if (a.shield) cout << " 护盾:" << a.shieldValue;
if (a.stunTurn > 0) cout << "[眩晕剩余" << a.stunTurn << "回合]";
cout << endl;
cout <<left << setw (12) << b.name
<< "HP:" << setw (5) << b.hp << "/" << b.maxHp
<< " MP:" << setw (4) << b.mp << "/" << b.maxMp;
if (b.shield) cout << " 护盾:" << b.shieldValue;
if (b.stunTurn > 0) cout << "[眩晕剩余" << b.stunTurn << "回合]";
cout << endl;
cout << "----------------------------------------------------" << endl;
}
void showBattleResult (Hero p1, Hero p2, int totalRound)
{
Sleep (800);
cout << "\n\n";
cout << "┏━━━━━━━━━━━━━━━━━━━━━━━━━┓\n";
cout << "┃ ?? 战 斗 结 算?? ┃\n";
cout << "┗━━━━━━━━━━━━━━━━━━━━━━━━━┛\n";
cout << "总战斗回合:" << totalRound << "\n\n";
cout << "【" << p1.name << "】最终状态 \n";
cout << "生命:" << p1.hp << "/" << p1.maxHp << "\n";
cout << "灵力:" << p1.mp << "/" << p1.maxMp << "\n";
cout << "护盾值:" << p1.shieldValue << "\n";
cout << "攻击力:" << p1.attack << "| 防御力:" << p1.defense << "\n";
cout <<"暴击率:" << fixed << setprecision (1) << p1.critRate100 << "%\n";
if (p1.hp <=0) cout << "状态:?? 战败 \n";
else cout << "状态:? 存活 \n";
cout << "----------------------------------------\n";
cout << "【" << p2.name << "】最终状态 \n";
cout << "生命:" << p2.hp << "/" << p2.maxHp << "\n";
cout << "灵力:" << p2.mp << "/" << p2.maxMp << "\n";
cout << "护盾值:" << p2.shieldValue << "\n";
cout << "攻击力:" << p2.attack << "| 防御力:" << p2.defense << "\n";
cout <<"暴击率:" << fixed << setprecision (1) << p2.critRate100 << "%\n";
if (p2.hp <=0) cout << "状态:?? 战败 \n";
else cout << "状态:? 存活 \n";
cout << "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n";
}
bool attackTarget (Hero &attacker, Hero &defender)
{
if (attacker.mp <= 0)
{
cout << attacker.name << "灵力耗尽,无法发起攻击!" << endl;
return false;
}
Sleep(600);
bool crit = false;
int baseDmg = attacker.attack;
int cost = 12 * mpRate;
if(cost > attacker.mp) cost = attacker.mp;
attacker.mp -= cost;
if(attacker.mp < 0) attacker.mp = 0;
double randCrit = (rand() % 1000) / 1000.0;
if(randCrit < attacker.critRate)
{
baseDmg *= 2;
crit = true;
}
int damage = baseDmg - defender.defense;
if(damage < 10) damage = 10;
if(defender.shield && defender.shieldValue > 0)
{
if(defender.shieldValue >= damage)
{
defender.shieldValue -= damage;
damage = 0;
}
else
{
damage -= defender.shieldValue;
defender.shieldValue = 0;
defender.shield = false;
}
}
defender.hp -= damage;
if(defender.hp < 0) defender.hp = 0;
cout << attacker.name;
if (crit) cout << " 触发暴击!";
if (attacker.name == "鲤逍遥"){
cout << " 手腕一转长剑横斩,剑气掠向对手,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "鹊瑶"){
cout << " 羽翼扇动,一簇灼热凤火飞向敌人,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "鹰乘风"){
cout << " 利爪裹挟劲风迎面抓击,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "熊莫开"){
cout << " 厚重熊掌狠狠拍向敌人,地面微微震颤,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "蛮神爪牙"){
cout << " 布满戾气的利爪狠狠撕咬,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "梅寒衣"){
cout << " 寒剑轻挥,一缕凛冽寒气刺向敌方,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "兔暗香"){
cout << " 身形一闪,袖中短刃悄无声息刺出,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "鲤余欢"){
cout << " 手引水流,一道锋利水刃飞速切向对手,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "剑无忌"){
cout << " 剑光一闪,快剑直刺敌人破绽,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else if (attacker.name == "蛮神使者"){
cout << " 巨斧呼啸抡出,带着蛮神之力劈砍,造成" << damage << "点伤害,消耗灵力" << cost << endl;
} else {
cout << " 挥出攻击,造成" << damage << "点伤害,消耗灵力" << cost << endl;
}
return crit;
}
int getSkillWeight(Hero &h)
{
double hpRate = (double)h.hp / h.maxHp;
double mpRateHero = (double)h.mp / h.maxMp;
int base = 40;
if(hpRate < 0.30){
base += 35;
}else if(hpRate < 0.50){
base += 20;
}else if(hpRate > 0.85){
base -= 10;
}
if(h.shield && h.shieldValue > 0){
base -= 15;
}
if(mpRateHero < 0.25){
base += 22;
}else if(mpRateHero < 0.50){
base += 10;
}else if(mpRateHero > 0.85){
base += 5;
}
if (h.name == "熊莫开"){
base += 12;
} else if (h.name == "鹊瑶"){
base += 10;
} else if (h.name == "兔暗香" || h.name == "鹰乘风"){
base -= 8;
}
if(base < 15) base = 15;
if(base > 85) base = 85;
return base;
}
bool useSkill(Hero &attacker, Hero &defender, int sk = -1)
{
Sleep(700);
// sk = -1 表示 AI 随机选技能;sk >= 0 表示玩家指定具体技能
if (sk == -1)
{
vector<int> skillPool;
double hpRate = (double)attacker.hp / attacker.maxHp;
double mpRateHero = (double)attacker.mp / attacker.maxMp;
skillPool.push_back(0);
skillPool.push_back(1);
skillPool.push_back(2);
if (mpRateHero < 0.80 || hpRate < 0.50)
{
skillPool.push_back(3);
}
int skIndex = rand() % skillPool.size();
sk = skillPool[skIndex];
}
const int costMeditate = 12 * ::mpRate;
if (attacker.name == "鲤逍遥")
{
if (sk == 0)
{
int boostAtk = 10 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鲤逍遥拔剑出鞘,剑气激荡,施展【逍遥剑决】!消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attacker.critRate += 0.05;
attackTarget (attacker, defender);
attacker.critRate -= 0.05;
attacker.attack -= 6 * attack;
}
else if (sk == 1)
{
int skillDmg = attacker.attack * 30;
int cost = skillDmg/10;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鲤逍遥双手挽剑,万千剑光席卷而出,汇聚成巨龙!【天剑龙吟】!消耗灵力" << cost << endl;
int dmg = skillDmg - defender.defense;
if (dmg < 15) dmg = 15;
if (defender.shield && defender.shieldValue > 0)
{
if (defender.shieldValue >= dmg){ defender.shieldValue -= dmg; dmg = 0; }
else { dmg -= defender.shieldValue; defender.shieldValue = 0; defender.shield = false; }
}
defender.hp -= dmg;
if (defender.hp < 0) defender.hp = 0;
cout << "剑之巨龙轰击敌人,造成" << dmg << "点伤害!" << endl;
}
else if (sk == 2)
{
int shieldGain = 300 * hp;
int cost = shieldGain/10;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鲤逍遥凝神静气,剑意环绕周身!【剑气屏障】消耗灵力" << cost << endl;
attacker.shield = true;
attacker.shieldValue += shieldGain;
cout << "一层厚实的剑意护盾包裹自身!护盾 +" << shieldGain << endl;
}
else if (sk == 3)
{
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "鲤逍遥闭目凝神【冥想】,心神沉静,调和体内力量!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else if (attacker.name == "鹊瑶")
{
if (sk == 0)
{
int boostAtk = 9 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鹊瑶皇火喷涌,凌空飞掠!【皇火焚烧】!消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 7 * attack;
}
else if (sk == 1)
{
int healAmt = 1000 * hp;
int cost = healAmt/10;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鹊瑶舒展羽翼,柔和白光洒落全身!【涅槃道义】!消耗灵力" << cost << endl;
if (attacker.hp + healAmt > attacker.maxHp) {
cout << "涅槃重生恢复所有伤势,恢复" << attacker.maxHp - attacker.hp << "点生命!" << endl;
attacker.hp = attacker.maxHp;
}
else {
cout << "涅槃重生恢复大量伤势,恢复" << healAmt << "点生命!" << endl;
attacker.hp += healAmt;
}
}
else if (sk == 2)
{
int cost = 25 * ::mpRate;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鹊瑶眼神深邃,【皇者威压】!凤凰血脉镇压对手!消耗灵力" << cost << endl;
if (rand () % 100 < 42){
defender.stunTurn = 3; // 设置眩晕3回合
cout << defender.name << "被死死压制,陷入眩晕!" << endl;
} else {
cout << defender.name << "奋力挣脱了血脉压制!" << endl;
}
}
else if (sk == 3)
{
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "鹊瑶闭目凝神【冥想】,凤火缓缓流转体内!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else if (attacker.name == "鹰乘风")
{
if (sk == 0){
int boostAtk = 6 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鹰乘风双翼振起,如风一般冲杀向前!【疾风斩】消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 4 * attack;
} else if (sk == 1){
int dmgVal = attacker.attack * 1.32;
int cost = dmgVal;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鹰乘风直冲云霄,自高空俯冲而下!【凌空突袭】!消耗灵力" << cost << endl;
int dmg = dmgVal - defender.defense;
if (dmg < 12) dmg = 12;
defender.hp -= dmg;
if (defender.hp < 0) defender.hp = 0;
cout << "猛烈俯冲撞击对手,造成" << dmg << "点伤害!" << endl;
} else if (sk == 2){
int boostAtk = 45 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鹰乘风目光锐利,激发体内野性!【锐攻】!消耗灵力" << cost << endl;
attacker.attack += boostAtk;
cout << "战意升腾,自身攻击力大幅提升!攻击 +" << boostAtk << endl;
} else if (sk == 3){
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "鹰乘风闭目凝神【冥想】,平复躁动战意!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else if (attacker.name == "熊莫开")
{
if (sk == 0){
int boostAtk = 8 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "熊莫开沉重身躯猛冲,【巨力冲撞】!消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 8 * attack;
} else if (sk == 1){
int shieldGain = 380 * hp;
int cost = shieldGain/10;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "熊莫开绷紧浑身肌肉,硬甲覆盖全身!【坚甲】消耗灵力" << cost << endl;
attacker.shield = true;
attacker.shieldValue += shieldGain;
cout << "厚重铠甲生成护盾保护自己!护盾 +" << shieldGain << endl;
} else if (sk == 2){
int boostDef = 40 * defense;
int cost = boostDef;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "熊莫开仰天怒吼,震荡四方!【怒吼】消耗灵力" << cost << endl;
attacker.defense += boostDef;
cout << "怒吼激发肉身潜能,防御大幅提高!防御 +" << boostDef << endl;
} else if (sk == 3){
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "熊莫开闭目凝神【冥想】,粗重呼吸平稳下来!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else if (attacker.name == "梅寒衣")
{
if (sk == 0){
int boostAtk = 6 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "梅寒衣手中寒剑绽放冷光,【寒梅剑】!消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 4 * attack;
} else if (sk == 1){
int cost = 45 * ::mpRate;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "梅寒衣挥剑释放刺骨寒气!【冰封】!消耗灵力" << cost << endl;
if (rand () % 100 < 38){
defender.stunTurn = 3; // 设置眩晕3回合
cout << defender.name << "被寒冰冻结,动弹不得!" << endl;
} else {
cout << defender.name << "抵抗住冰冷寒气!" << endl;
}
} else if (sk == 2){
int boostDef = 32 * defense;
int cost = boostDef;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "梅寒衣心如止水,冰心护体!【冰心】消耗灵力" << cost << endl;
attacker.defense += boostDef;
cout << "清冷心境强化自身防御!防御 +" << boostDef << endl;
} else if (sk == 3){
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "梅寒衣闭目凝神【冥想】,寒气内敛于心!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else if (attacker.name == "兔暗香")
{
if (sk == 0){
int boostAtk = 6 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "兔暗香身形飘忽,化作一道黑影!【影袭】!消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 4 * attack;
} else if (sk == 1){
int boostAtk = 40 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "兔暗香脚步翻飞,身法全开!【速攻】消耗灵力" << cost << endl;
attacker.attack += boostAtk;
cout << "极速身法让攻击力得到提升!攻击 +" << boostAtk << endl;
} else if (sk == 2){
int cost = 30 * ::mpRate;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "兔暗香消失在暗影之中,伺机寻找弱点!【迷踪】消耗灵力" << cost << endl;
if (attacker.critRate <= 0.95){
attacker.critRate += 0.10;
cout << "隐匿身形,暴击概率上升!" << endl;
}
else {
attacker.attack += 40 * attack;
cout << "隐匿身形,攻击力上升!" << endl;
}
} else if (sk == 3){
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "兔暗香闭目凝神【冥想】,暗影缓缓流动!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else if (attacker.name == "鲤余欢")
{
if (sk == 0){
int boostAtk = 6 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鲤余欢身形灵动,水刃一闪而过!【鱼龙闪】消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 4 * attack;
} else if (sk == 1){
int dmgVal = attacker.attack * 1.35;
int cost = dmgVal;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鲤余欢张口喷出汹涌水浪!【龙息】!消耗灵力" << cost << endl;
int dmg = dmgVal - defender.defense;
if (dmg < 15) dmg = 15;
defender.hp -= dmg;
if (defender.hp < 0) defender.hp = 0;
cout << "汹涌龙息冲击敌人,造成" << dmg << "点伤害!" << endl;
} else if (sk == 2){
int shieldGain = 290 * hp;
int cost = shieldGain/10;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "鲤余欢调动水流环绕周身!【御水盾】消耗灵力" << cost << endl;
attacker.shield = true;
attacker.shieldValue += shieldGain;
cout << "流动水盾护住自身!护盾 +" << shieldGain << endl;
} else if (sk == 3){
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "鲤余欢闭目凝神【冥想】,水流在身周静静回旋!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else if (attacker.name == "剑无忌")
{
if (sk == 0){
int boostAtk = 7 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "剑无忌剑光快到肉眼难辨!【快剑】!消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 4 * attack;
} else if (sk == 1){
int cost = 45 * ::mpRate;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "剑无忌一剑斩向敌人铠甲弱点!【破甲】!消耗灵力" << cost << endl;
defender.defense -= 28 * attack;
if (defender.defense < 20) defender.defense = 20;
cout << "击破对手防具,敌人防御力下降!" << endl;
} else if (sk == 2){
int cost = 30 * ::mpRate;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "剑无忌全身心融入剑道,【剑意】升腾!消耗灵力" << cost << endl;
if (attacker.critRate <= 0.95){
attacker.critRate += 0.11;
cout << "剑意加持,暴击概率提高!" << endl;
}
else {
attacker.attack += 40 * attack;
cout << "剑意加持,攻击力提高!" << endl;
}
} else if (sk == 3){
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "剑无忌闭目凝神【冥想】,剑心归于平静!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else if (attacker.name == "蛮神使者")
{
if (sk == 0){
int boostAtk = 10 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "蛮神使者高举巨斧,蛮力横扫!【蛮神战斧】消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 10 * attack;
} else if (sk == 1){
int healAmt = 200 * hp;
int cost = healAmt/10;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "蛮神使者呼唤蛮神之力,黑暗能量涌入体内!【蛮神赐福】消耗灵力" << cost << endl;
attacker.hp += healAmt;
if (attacker.hp > attacker.maxHp) attacker.hp = attacker.maxHp;
cout << "蛮神力量修复伤势,恢复" << healAmt << "点生命!" << endl;
} else if (sk == 2){
int boostAtk = 35 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "蛮神使者释放狂暴气场!【狂暴威压】消耗灵力" << cost << endl;
attacker.attack += boostAtk;
cout << "狂暴气息让自身攻击上升!攻击 +" << boostAtk << endl;
} else if (sk == 3){
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "蛮神使者闭目凝神【冥想】,压制体内狂暴蛮力!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
else // 蛮神爪牙
{
if (sk == 0){
int boostAtk = 10 * attack;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "蛮神爪牙利爪撕裂空间!【利爪撕裂】消耗灵力" << cost << endl;
attacker.attack += boostAtk;
attackTarget (attacker, defender);
attacker.attack -= 10 * attack;
} else if (sk == 1){
int cost = 45 * ::mpRate;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "蛮神爪牙引动蛮神浊气侵蚀对手!【浊气腐蚀】消耗灵力" << cost << endl;
defender.defense -= 22 * attack;
if (defender.defense < 20) defender.defense = 20;
cout << "浊气腐蚀防具,敌人防御力降低!" << endl;
} else if (sk == 2){
int boostAtk = 30;
int cost = boostAtk;
if (cost > attacker.mp) return false;
attacker.mp -= cost;
cout << "蛮神爪牙激发蛮神血脉!【狂化】!消耗灵力" << cost << endl;
attacker.attack += boostAtk;
cout << "狂化状态下攻击力提升!攻击 +" << boostAtk << endl;
} else if (sk == 3){
if (costMeditate > attacker.mp) return false;
attacker.mp -= costMeditate;
int restoreMp = (rand () % 11 + 90) * ::mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if (attacker.mp + restoreMp > attacker.maxMp) restoreMp = attacker.maxMp - attacker.mp;
if (attacker.hp + restoreHp > attacker.maxHp) restoreHp = attacker.maxHp - attacker.hp;
attacker.mp += restoreMp;
attacker.hp += restoreHp;
cout << "蛮神爪牙闭目凝神【冥想】,躁动戾气稍稍平息!消耗灵力" << costMeditate << endl;
cout << "恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
}
}
if(attacker.mp < 0) attacker.mp = 0;
return true;
}
// 处理一个角色回合,包含眩晕计数递减
void handleOneTurn(Hero &unit, Hero &enemy)
{
cout << "\n>>" << unit.name << "的回合" << endl;
Sleep (800);
if (unit.stunTurn > 0)
{
cout << unit.name << "被眩晕困住,浑身无法动弹!剩余眩晕回合:" << unit.stunTurn << endl;
unit.stunTurn -= 1; //眩晕回合?1
Sleep (700);
return;
}
if (unit.mp <= 0)
{
cout << unit.name << "灵力耗尽,无法行动,只能冥想回气!" << endl;
int restoreMp = (rand () % 11 + 90) * mpRate;
int restoreHp = (rand () % 41 + 10) * hp;
if(unit.mp + restoreMp > unit.maxMp) restoreMp = unit.maxMp - unit.mp;
if(unit.hp + restoreHp > unit.maxHp) restoreHp = unit.maxHp - unit.hp;
unit.mp += restoreMp;
unit.hp += restoreHp;
cout << unit.name << "被迫进入【冥想】,恢复灵力" << restoreMp << "点,恢复生命" << restoreHp << "点。" << endl;
return;
}
int skillProb = getSkillWeight(unit);
bool tryCast = false;
if(rand() % 100 < skillProb)
{
tryCast = useSkill(unit, enemy);
}
if(!tryCast)
{
attackTarget(unit, enemy);
}
}
void battleRound (Hero &a, Hero &b)
{
handleOneTurn(a,b);
if(b.hp <= 0) return;
handleOneTurn(b,a);
}
//AI vs AI 全自动对战,返回战斗总回合数
int battleEVE(Hero &a, Hero &b)
{
int roundCount = 1;
while(true)
{
cout << "\n===== 第" << roundCount << "回合 =====" << endl;
showStatus(a,b);
battleRound(a,b);
if(a.hp <= 0 || b.hp <=0)
{
showStatus(a,b);
break;
}
roundCount++;
}
return roundCount;
}
//PVE:玩家控制a,AI控制b,返回回合数
int battlePVE(Hero &player, Hero &aiEnemy)
{
int roundCount = 1;
while(true)
{
cout << "\n===== 第" << roundCount << "回合 =====" << endl;
showStatus(player, aiEnemy);
//玩家回合
cout << "\n=====玩家【" << player.name << "】回合=====" << endl;
Sleep(400);
if(player.stunTurn > 0)
{
cout << player.name << "被眩晕,无法行动!剩余眩晕:" << player.stunTurn << endl;
player.stunTurn--;
}
else
{
while(true)
{
int op;
cout << "\n请选择行动:\n";
cout << "1 - 普通攻击\n";
cout << "2 - 释放技能(可选具体技能)\n";
cout << "3 - 冥想\n";
cout << "输入选择:";
cin >> op;
if(op == 1)
{
attackTarget(player, aiEnemy);
break;
}
else if(op == 2)
{
cout << "\n===== 技能列表 =====" << endl;
cout << "0 - 技能一(强化普攻)" << endl;
cout << "1 - 技能二(大招/特殊效果)" << endl;
cout << "2 - 技能三(被动增益/控制)" << endl;
cout << "3 - 冥想(恢复灵力和生命)" << endl;
int skid;
cout << "请输入技能编号(0~3):";
cin >> skid;
if(skid < 0 || skid > 3)
{
cout << "无效技能编号,请重新选择!" << endl;
continue;
}
if(useSkill(player, aiEnemy, skid))
{
break;
}
else
{
cout << "灵力不足,释放失败,请重新选择行动!" << endl;
}
}
else if(op == 3)
{
useSkill(player, aiEnemy, 3);
break;
}
else
{
cout << "无效输入,请重新输入!" << endl;
}
}
}
//AI敌人回合
handleOneTurn(aiEnemy, player);
if(player.hp <=0)
{
showStatus(player, aiEnemy);
break;
}
roundCount++;
}
return roundCount;
}
//PVP双人对战,p1玩家1,p2玩家2,返回回合数
int battlePVP(Hero &p1, Hero &p2)
{
int roundCount = 1;
while(true)
{
cout << "\n===== 第" << roundCount << "回合 =====" << endl;
showStatus(p1,p2);
//玩家1回合
cout << "\n=====玩家1【" << p1.name << "】回合=====" << endl;
Sleep(400);
if(p1.stunTurn > 0)
{
cout << p1.name << "被眩晕,无法行动!剩余眩晕:" << p1.stunTurn << endl;
p1.stunTurn--;
}
else
{
while(true)
{
int op;
cout << "\n请选择行动:\n";
cout << "1 - 普通攻击\n";
cout << "2 - 释放技能(可选具体技能)\n";
cout << "3 - 冥想\n";
cout << "输入选择:";
cin >> op;
if(op == 1)
{
attackTarget(p1, p2);
break;
}
else if(op == 2)
{
cout << "\n===== 技能列表 =====" << endl;
cout << "0 - 技能一(强化普攻)" << endl;
cout << "1 - 技能二(大招/特殊效果)" << endl;
cout << "2 - 技能三(被动增益/控制)" << endl;
cout << "3 - 冥想(恢复灵力和生命)" << endl;
int skid;
cout << "请输入技能编号(0~3):";
cin >> skid;
if(skid < 0 || skid > 3)
{
cout << "无效技能编号,请重新选择!" << endl;
continue;
}
if(useSkill(p1, p2, skid))
{
break;
}
else
{
cout << "灵力不足,释放失败,请重新选择行动!" << endl;
}
}
else if(op == 3)
{
useSkill(p1, p2, 3);
break;
}
else
{
cout << "无效输入,请重新输入!" << endl;
}
}
}
if(p2.hp <= 0)
{
showStatus(p1,p2);
break;
}
system("pause");
//玩家2回合
cout << "\n=====玩家2【" << p2.name << "】回合=====" << endl;
Sleep(400);
if(p2.stunTurn > 0)
{
cout << p2.name << "被眩晕,无法行动!剩余眩晕:" << p2.stunTurn << endl;
p2.stunTurn--;
}
else
{
while(true)
{
int op;
cout << "\n请选择行动:\n";
cout << "1 - 普通攻击\n";
cout << "2 - 释放技能(可选具体技能)\n";
cout << "3 - 冥想\n";
cout << "输入选择:";
cin >> op;
if(op == 1)
{
attackTarget(p2, p1);
break;
}
else if(op == 2)
{
cout << "\n===== 技能列表 =====" << endl;
cout << "0 - 技能一(强化普攻)" << endl;
cout << "1 - 技能二(大招/特殊效果)" << endl;
cout << "2 - 技能三(被动增益/控制)" << endl;
cout << "3 - 冥想(恢复灵力和生命)" << endl;
int skid;
cout << "请输入技能编号(0~3):";
cin >> skid;
if(skid < 0 || skid > 3)
{
cout << "无效技能编号,请重新选择!" << endl;
continue;
}
if(useSkill(p2, p1, skid))
{
break;
}
else
{
cout << "灵力不足,释放失败,请重新选择行动!" << endl;
}
}
else if(op == 3)
{
useSkill(p2, p1, 3);
break;
}
else
{
cout << "无效输入,请重新输入!" << endl;
}
}
}
if(p1.hp <= 0)
{
showStatus(p1,p2);
break;
}
system("pause");
roundCount++;
}
return roundCount;
}
int main ()
{
srand((unsigned int)time(NULL));
int t;
cout << "请输入对局场数:";
cin >> t;
cout << endl;
while(t--)
{
cout << "===== 龙腾宇宙全自动对战模拟器 =====" << endl;
cout << "请选择对战模式:\n";
cout << "1 - EVE(AI vs AI,全自动对战)\n";
cout << "2 - PVE(玩家操作角色,AI操控对手)\n";
cout << "3 - PVP(双人玩家对战)\n";
int mode;
cout << "输入模式编号:";
cin >> mode;
cout << "【可选角色编号】" << endl;
cout << "1 鲤逍遥 2 鹊瑶 3 鹰乘风 4 熊莫开 5 蛮神爪牙" << endl;
cout << "6 梅寒衣 7 兔暗香 8 鲤余欢 9 剑无忌 10 蛮神使者" << endl;
int x, y;
cout << "\n请输入第一个对战角色编号:";
cin >> x;
cout << "请输入第二个对战角色编号:";
cin >> y;
cout << endl;
cout <<"请输入角色血量倍率 (整数):";
cin >> hp;
cout << "请输入角色攻击倍率 (整数):";
cin >> attack;
cout << "请输入角色防御倍率 (整数):";
cin >> defense;
cout << "请输入角色灵力倍率 (整数):";
cin >> mpRate;
if(x < 1 || x > 10) x = 1;
if(y < 1 || y > 10) y = 2;
Hero p1 = createHero(x);
Hero p2 = createHero(y);
cout << "\n==========对战开始!" << endl;
if(mode == 1)
{
battleEVE(p1, p2);
}
else if(mode == 2)
{
battlePVE(p1, p2);
}
else if(mode == 3)
{
battlePVP(p1, p2);
}
cout << "\n================ 战斗结束 ================" << endl;
Sleep (1000);
if (p1.hp <= 0 && p2.hp <= 0)
{
cout << "双方全部倒下,战斗平局!" << endl;
}
else if (p1.hp > 0)
{
cout << "【胜利】" << p1.name << "取得本次对战胜利!" << endl;
}
else
{
cout << "【胜利】" << p2.name << "取得本次对战胜利!" << endl;
}
showBattleResult(p1, p2, 0);
cout << "========================================" << endl;
system("pause");
system("cls");
}
cout << "\n全部对局执行完毕,程序退出。\n";
return 0;
}
这里空空如也

















有帮助,赞一个