FFA(多人)(决斗类)
C++#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
using ll=long long;
struct player{
int magic_power,health_point;
string name;
int defense;
int captured;
int cnt=0;
int pet[5];
string np[5];
int rk;
};
player a[100];
int n;
map<string,int> mp;
void work(){
for(int i=0;i<n;i++){
if(a[i].health_point<=0){
a[i].health_point=0;
}
else{
a[i].cnt=0;
for(int j=1;j<=4;j++){
if(a[i].pet[j]>0){
a[i].pet[++a[i].cnt]=a[i].pet[j];
a[i].np[a[i].cnt]=a[i].np[j];
if(a[i].cnt!=j){
a[i].pet[j]=0;
a[i].np[j]="";
}
}
}
}
}
}
int print(int op){
int liv=0;
for(int i=0;i<n;i++){
if(op){
cout<<a[i].name<<"\n";
if(a[i].health_point==0){
cout<<"状态:死亡\n";
cout<<"被 "<<a[a[i].captured].name<<" 击杀\n";
cout<<"排名:"<<a[i].rk<<"\n";
}
else{
cout<<"血量:"<<a[i].health_point<<"\n";
cout<<"魔法值:"<<a[i].magic_power<<"\n";
cout<<"防御牌:"<<a[i].defense<<"\n";
cout<<"宠物数:"<<a[i].cnt<<"\n";
for(int j=1;j<=a[i].cnt;j++){
cout<<a[i].pet[j]<<"("<<a[i].np[j]<<")\n";
}
}
cout<<"\n";
}
liv+=(a[i].health_point>0);
}
if(op){
cout<<"存活的人数为:"<<liv<<"\n";
}
return liv;
}
void add(int id,int x,string s){
if(a[id].cnt<4){
a[id].pet[++a[id].cnt]=x;
a[id].np[a[id].cnt]=s;
}
else{
int pos=1;
for(int i=2;i<=3;i++){
if(a[id].pet[i]<a[id].pet[pos]){
pos=i;
}
}
if(a[id].pet[pos]<x){
a[id].pet[pos]=x;
a[id].np[pos]=s;
}
}
}
signed main(){
//HAPPY!
srand(time(0));
while(1){
mp.clear();
cout<<"几人\n";
cin>>n;
cout<<"名字\n";
for(int i=0;i<n;i++){
cin>>a[i].name;
mp[a[i].name]=i;
a[i].health_point=150;
a[i].defense=a[i].magic_power=a[i].cnt=0;
a[i].captured=-1;
a[i].rk=0;
for(int j=1;j<=4;j++){
a[i].pet[j]=0;
}
}
system("cls");
cout<<"游戏加载中...\n";
Sleep(1000);
int id=0;
while(1){
system("cls");
work();
int lst=print(1);
if(lst==1){
for(int i=0;i<n;i++){
if(a[i].health_point>0){
cout<<a[i].name<<" 赢了!!!\n";
cout<<a[i].name<<" 666\n";
cout<<a[i].name<<" 排名: 1\n";
for(int rk=2;rk<=n;rk++){
for(int i=0;i<n;i++){
if(rk==a[i].rk){
cout<<a[i].name<<" 排名: "<<rk<<"\n";
}
}
}
Sleep(5000);
system("cls");
break;
}
}
break;
}
cout<<"到 "<<a[id].name<<" 走了\n";
cout<<"1(普攻)/2(魔法攻击)/3(抽卡)\n";
int op;
cin>>op;
if(op==1){
string name;int pos;
cin>>name>>pos;
if(a[mp[name]].defense){
cout<<name<<" 使用防御牌\n";
a[mp[name]].defense--;
}
else if(pos){
a[mp[name]].pet[pos]-=10;
cout<<a[id].name<<" 对 "<<name<<" 的第 "<<pos<<" 宠物造成 10 点伤害\n";
int Gain=rand()%(3)+3;
a[id].magic_power+=Gain;
cout<<"魔法值加 "<<Gain<<"\n";
}
else if(rand()%(3)==1){
cout<<name<<" 躲过攻击\n";
}
else{
a[mp[name]].health_point-=10;
cout<<a[id].name<<" 对 "<<name<<" 本人造成 10 点伤害\n";
int Gain=rand()%(3)+3;
a[id].magic_power+=Gain;
cout<<"魔法值加 "<<Gain<<"\n";
}
}
else if(op==2){
if(a[id].magic_power>=20){
a[id].magic_power-=20;
string name;int pos;
cin>>name>>pos;
if(a[mp[name]].defense>=5){
cout<<name<<" 使用 5 防御牌来抵御攻击\n";
a[mp[name]].defense-=5;
continue;
}
if(!pos){
cout<<a[id].name<<" 对 "<<name<<" 本人造成 30 点伤害!!!\n";
a[mp[name]].health_point-=30;
}
else{
a[mp[name]].pet[pos]-=30;
cout<<a[id].name<<" 对 "<<name<<" 的第 "<<pos<<" 宠物造成 30 点伤害!!!\n";
cout<<"对此名的其他宠物造成 10 点伤害!!!\n";
for(int i=1;i<=a[mp[name]].cnt;i++){
if(i!=pos){
a[mp[name]].pet[i]-=10;
}
}
}
}
}
else{
int random_option=rand()%(20);
if(random_option<3){
cout<<a[id].name<<" 使用[桃]\n";
int x=rand()%(11)+5;
cout<<"加 "<<x<<" 生命值\n";
a[id].health_point+=x;
}
else if(random_option<3+2){
cout<<a[id].name<<" 使用[防御工事]\n";
int x=rand()%(2)+2;
cout<<"加 "<<x<<" 张防御牌\n";
a[id].defense+=x;
}
else if(random_option<3+2+3){
cout<<a[id].name<<" 使用[魔法阵]\n";
int x=rand()%(3)+5;
cout<<"加 "<<x<<" 魔法值\n";
a[id].magic_power+=x;
}
else if(random_option<3+2+3+1){
cout<<a[id].name<<" 使用[燃烧弹]\n";
cout<<"对自己以外的所有宠物造成 10 点伤害!!!\n";
for(int i=0;i<n;i++){
if(i!=id){
for(int j=1;j<=a[i].cnt;j++){
a[i].pet[j]-=10;
}
}
}
}
else if(random_option<3+2+3+1+1){
cout<<a[id].name<<" 使用[保养]\n";
cout<<"加 5 生命值和使自己的所有宠物加 10 点血量!\n";
a[id].health_point+=5;
for(int i=1;i<=a[id].cnt;i++){
a[id].pet[i]+=10;
}
}
else if(random_option<3+2+3+1+1+2){
cout<<"无\n";
}
else if(random_option<3+2+3+1+1+2+3){
cout<<a[id].name<<" 使用[乘虚而入]\n";
string name;int pos;
cin>>name>>pos;
int x=rand()%(5)+13;
if(!pos){
cout<<a[id].name<<" 对 "<<name<<" 本人造成 "<<x<<" 点伤害\n";
a[mp[name]].health_point-=x;
}
else{
cout<<a[id].name<<" 对 "<<name<<" 的第 "<<pos<<" 宠物造成 "<<x<<" 点伤害\n";
a[mp[name]].pet[pos]-=x;
}
}
else if(random_option<3+2+3+1+1+2+3+2){
cout<<a[id].name<<" 使用[冬季战争]\n";
cout<<"对所有人和宠物造成 8 点伤害\n";
for(int i=0;i<n;i++){
a[i].health_point-=8;
for(int j=1;j<=a[i].cnt;j++){
a[i].pet[j]-=8;
}
}
}
else if(random_option<3+2+3+1+1+2+3+2+2){
cout<<a[id].name<<" 使用[召唤]\n";
cout<<"给你的宠物取一个新名字吧!\n";
string s;
cin>>s;
cout<<"宠物加 1\n";
int x=rand()%(11)+15;
cout<<"其血量为: "<<x<<"\n";
add(id,x,s);
}
else{
cout<<a[id].name<<" 使用[桃园结义]\n";
cout<<"所有人加 10 生命值\n";
for(int i=0;i<n;i++){
if(a[i].health_point>0){
a[i].health_point+=10;
}
}
}
}
Sleep(1000);
system("cls");
for(int i=0;i<n;i++){
if(a[i].health_point<=0 && a[i].captured==-1){
a[i].captured=id;
a[i].rk=lst;
if(a[id].health_point>0){
add(id,25,a[i].name);
for(int j=1;j<=a[i].cnt;j++){
add(id,a[i].pet[j],a[i].np[j]);
}
}
}
}
work();
print(1);
cout<<a[id].name<<" 的回合结束了\n";
if(a[id].cnt){
int x=a[id].cnt*3;
cout<<a[id].name<<" 的所有宠物对其他人造成 "<<x<<" 点伤害\n";
for(int i=0;i<n;i++){
if(i!=id){
a[i].health_point-=x;
}
}
}
for(int i=0;i<n;i++){
if(a[i].health_point<=0 && a[i].captured==-1){
a[i].captured=id;
a[i].rk=lst;
if(a[id].health_point>0){
add(id,25,a[i].name);
for(int j=1;j<=a[i].cnt;j++){
add(id,a[i].pet[j],a[i].np[j]);
}
}
}
}
work();
Sleep(1000);
work();
if(print(0)==0){
cout<<"无人胜利...\n";
for(int rk=1;rk<=n;rk++){
for(int i=0;i<n;i++){
if(a[i].rk==rk){
cout<<a[i].name<<" 排名: "<<rk<<"\n";
}
}
}
Sleep(5000);
system("cls");
break;
}
id=(id+1)%n;
while(a[id].health_point<=0){
id=(id+1)%n;
}
}
}
return 0;
}