//有略微修改
#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);
}
// 处理一个角色回合,包含眩晕计数递减
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;
}
//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);
}
//PVP双人对战,p1玩家1,p2玩家2,返回回合数
int battlePVP(Hero &p1, Hero &p2)
{
int roundCount = 1;
while(true)
{
cout << "\n===== 第" << roundCount << "回合 =====" << endl;
showStatus(p1,p2);
}
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);
}