二改
2026-08-06 14:26:48
发布于:浙江
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <windows.h>
#include <vector>
using namespace std;
const int N =1e5+10;
struct Node {
string name;
int hp;
int dm;
int fy;
bool state=true;
int kill=0;
int score=0;
int help=0;
int bj;
};
bool ck;
int n;
vector <Node > v(N+1);
int survive;
int random_(int mn, int mx) {
return (rand() % (mx - mn + 1)) + mn;
}
void color(int c) {
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, c);
}
string talot[]= {"无意义","愚者","女祭司","力量","倒吊人","高塔","太阳","月亮"};
void check(int tlp,int t) {
if (tlp == 1) {
v[t].hp -= v[t].dm/2;
cout << "|" << v[t].name << "|被愚者反噬 受到了" << "[" << v[t].dm/2 << "]" << "的伤害\n";
if (v[t].hp <= 0) {
cout << "|" << v[t].name << "| 已死亡";
survive -= 1;
v[t].state = false;
}
} else if (tlp == 2) {
cout << "无事发生\n";
} else if (tlp == 3) {
int x = random_(1,100);
cout << "|" << v[t].name << "|的攻击 增加了[" << x << "]点伤害\n";
v[t].dm += x;
} else if(tlp == 4) {
survive -= 1;
cout << "|" << v[t].name << "|抽到了";
color(14);
cout << "倒吊人";
color(11);
cout << "[" << v[t].name << "]已死亡\n";
v[t].state=false;
} else if(tlp == 5) {
int x = random_(1,50);
cout << "|" << v[t].name << "|的防御 增加了[" << x << "]点\n";
v[t].fy += x;
} else if (tlp == 6) {
int x = random_(1,80);
cout << "|" << v[t].name << "|的血量 增加了[" << x << "]点\n";
v[t].hp += x;
} else if (tlp == 7) {
int x = random_(1,80);
cout << "|" << v[t].name << "|的血量 减少了[" << x << "]点\n";
v[t].hp -= x;
if (v[t].hp <= 0) {
cout << "|" << v[t].name << "| 已死亡";
survive -= 1;
v[t].state = false;
}
}
color(7);
}
int main() {
srand(time(0));
cout << "请输入玩家人数:";
cin >> n;
Sleep(500);
for (int i = 1; i <= n; i ++) {
cout << "请输入玩家名称" << i << ":";
cin >> v[i].name;
v[i].hp = random_(150,400);
v[i].dm = random_(50,150);
v[i].fy = random_(50,100);
v[i].bj = random_(10,100);
Sleep(500);
}
cout << "---------------------------------------\n";
for (int i = 1; i <= n; i ++) {
cout << v[i].name << " HP[" << v[i].hp << "] 攻[" << v[i].dm << "] 防[" << v[i].fy << "] 暴击率[" << v[i].bj << "%]\n";
}
cout << "---------------------------------------\n";
survive=n;
bool vis[n][n];
for (int i = 1; i <= n; i ++) {
for (int j = 1; j <= n; j ++) {
vis[i][j] = false;
}
}
while (survive > 1) {
ck=false;
for (int i = 1; i <= n; i ++) {
int t = random_(1,n);
if (v[i].state == false || v[t].state == false) continue;
if (t == i) {
Sleep(500);
cout << "|" << v[i].name << "| 环顾四周,没有找到合适的目标..." << endl;
} else {
cout << "|" << v[i].name << "|" << "向" << "|" << v[t].name << "|" << " 起了攻击\n";
v[i].score += v[i].dm;
Sleep(500);
if (v[t].fy / 2 > 35) {
v[t].fy /= 2;
cout << "| " << v[t].name << " | 灵活地闪避了攻击!" << endl;
ck=true;
} else {
int b = random_(1,10);
int c = 1;
if (v[i].bj/10 <= b) {
cout << "触发暴击!";
c = 2;
}
cout << "|" << v[t].name << "|受到了";
if (vis[i][t] == false) v[i].help += 1;
vis[i][t]==true;
color(4);
cout<< "[" <<v[i].dm*c << "]";
color(7);
cout << "的伤害\n";
v[t].hp -= v[i].dm*c;
cout << v[t].name << "还剩|" << v[t].hp << "|点血\n";
}
if (v[t].hp <= 0) {
survive -= 1;
Sleep(1500);
color(10);
cout << ">>> " << v[t].name << " 被 " << v[i].name << " 击败了! <<<" << endl;
v[i].kill ++;
v[t].state=false;
int tlp = random_(1,7);
color(11);
cout << "|" << v[t].name << "|抽到的塔罗牌为:" ;
if (tlp == 4 || tlp == 2) color(14);
cout << talot[tlp] << "\n";
color(7);
int joker = random_(1,10);
if (joker >= 8) {
color(14);
cout << "小丑牌 [" << talot[tlp] << "] 牌不奏效\n";
}
if (tlp == 2 && joker < 8) {
Sleep(500);
color(10);
cout << "‌*** 奇迹发生!" << v[t].name << " 复活了! ***‌\n";
color(7);
v[t].hp = random_(150,400);
v[t].dm = random_(50,150);
v[t].fy = random_(50,100);
survive += 1;
v[t].state=true;
} else {
Sleep(500);
color(10);
cout << "... " << v[t].name << " 彻底倒下了。" << endl;
color(7);
}
} else {
if (ck == true) {
int tlp = random_(1,7);
color(11);
cout << "|" << v[t].name << "|抽到的塔罗牌为:" ;
if (tlp == 4) color(14);
cout << talot[tlp] << "\n";
Sleep(500);
int joker = random_(1,10);
if (joker >= 8) {
color(14) ;
cout << "小丑牌 [" << talot[tlp] << "]不奏效\n";
} else check(tlp,t);
color(7);
}
}
}
}
}
// system("cls");
cout << "\n=======================================" << endl;
cout << " 游 戏 结 束 " << endl;
cout << "=======================================" << endl;
if (survive == 0) {
cout << "所有玩家均阵亡,根据战绩评定..." << endl;
} else {
for (int i = 1; i <= n; i ++) {
if (v[i].state == true) {
cout << "|" << v[i].name << "|为胜者\n";
break;
}
}
}
cout << "---------------------------------------\n";
int id,ans=-INT_MAX;
for (int i = 1; i <= n; i ++) {
cout << "|" << v[i].name << "|" << "击败了[" << v[i].kill << "]个人 ," << "造成了[" << v[i].score << "]伤害 助攻[" << v[i].help << "]个人\n";
if (v[i].score > ans) {
ans = v[i].score;
id=i;
} else if (v[i].score == ans) {
if (v[i].kill > v[id].kill) {
id=i;
ans = v[i].score;
}
}
}
cout << "---------------------------------------\n";
cout << "|" << v[id].name << "|为MVP获得了:[" << ans << "]的分数,击败了[" << v[id].kill << "]个人 助攻[" << v[id].help << "]个人";
cout << "=======================================" << endl;
//system("pause");
return 0;
}
这里空空如也





















有帮助,赞一个