-
Bio
#include #include #include #include #include #include #include #include using namespace std; int health1 = 10, health2 = 15; int power1 = 2, power2 = 2; int cnt = 0,mmm=1; int mom1=0,mom2=0; int u=0,y=0,ooo=0,qqqq,kk=0; int qwertyuiop=0; void kkk(int x,int d1,int d2,int qw,int qe){ if(x0){ d1=8; qw+=2; } if(x1){ d2=8; qe+=2; } return; } void intro(){ srand(time(NULL));
cout << endl << endl; cout << "欢迎来到《龙战2》"<<endl<<endl; cout << "两人回合制游戏,每回合双方同时在“攻击、防御、集气、必杀···”九种行动中选一种。" << endl << endl; cout << "1. “生命”:每人 15 点生命,生命归 0 立即死亡;" << endl << endl; cout << "2. “伤害”:攻击造成 1 伤害,防御免除攻击伤害,互相攻击双方都不受伤害,必杀造成 3 伤害;" << endl << endl; cout << "3. “必杀”:必杀需消耗 2 “气”,双方同时必杀则相安无事,否则放必杀者给对手造成伤害,对手的行动无任何效果;" << endl << endl; cout << "4. “气”:防御对方攻击增加 1 气,集气且不受到伤害增加 1 气。" << endl << endl; cout << "5. “终结”:若对方生命小于3时可使用,每局只能用一次"<< endl << endl; cout << "6. “世界末日”:需消耗 4 “气”,可直接令对方死亡"<< endl << endl; cout << "7. “劫气”:抢走对方的“气”"<<endl<<endl; cout << "8. “大补血”:消耗1气,无攻击时可增2血,被动时另当别论"<<endl<<endl; cout << "9. “神的佑护”:可防御世界末日,必杀;反弹劫气,攻击,终结;需祭祀2气"<<endl<<endl; cout << "----------单挑开始,你是武将1,卢轩轩是武将2----------" << endl << endl; } namespace human{ int strategy() { cout << "用数字代表本回合武将1的行动:0必杀,1攻击,2防御,3集气,4劫气,5大补血,6终结,7世界末日,8神的保佑" << endl; int x = 0; if (!(cin >> x)){ x = 0; getchar();
} return x; } } double rd(double l, double r){ return rand() * 1.0 / RAND_MAX * (r - l) + l; } int rdz(int l, int r){ return (int)(1.0 * rand() / RAND_MAX * (r - l) + l); } namespace ai{ int strategy(){ if(health1<=1){ return 6; } if (power2>=4){ if(health1<=8&&power1<2) return 7; else{ double pct=1.0/(health1-8); if(rd(0,1)<=pct) { return 7; } else goto E; } } E: if(power2>=2){ if(health1<=4){ return 0; } else{ double r1=rd(0,1),r2=rd(0,1); if(r1>=r2) return 0; goto EE; } } EE: if(power1>=4){ if(health2<=8){ if(power2>=2){ double pct=rd(0,0.3); if(rd(0,1)>=pct) return 8; else{ goto GG; } } } else{ double pct=rd(0,0.5); if(power2>=2&&rd(0,1)>=pct) return 8; else{ goto GG; } } } GG: int xl = health2; double g = rd(0, 1); double pct = ((1.0 - xl / 15.0) * 0.7); if(g<=pct&&power2>=1) return 5; else{ return rdz(1, 4); } } }//片段5 根据双方行动, 执行一回合的对战 bool fight(int d1, int d2){ if (d1 < 0 || d1 > 8){ cout << "【【【武将1没有这种策略啦~重新开始回合" << cnt << "!】】】" << endl; return true;
}
if ((d1 == 0 && power1 < 2)){ cout << "【【【武将1不够气来放必杀!重新开始回合" << cnt << "!】】】" << endl; return true;
} if(d1==7 && power1<4){ cout << "【【【武将1不够气来放末日!重新开始回合" << cnt << "!】】】" << endl; return true;} if (d1==5&&power1<1){ cout << "【【【武将1没气回血啦~重新开始回合" << cnt << "!】】】" << endl; return true; } if (d1==8&&power1<2){ cout << "【【【武将1没气保佑啦~重新开始回合" << cnt << "!】】】" << endl; return true; } if(d2==6){ cout<<"【【【武将1死了!】】】"<<"\n"; health1=0; return 0; } u=0; y=0; srand((int)time(NULL)); int rrr=rand()%8; int yyy=rand()%2 ; u=rrr; y=yyy; if(rrr==5)kkk(yyy,d1,d2,power1,power2); cout << "【【【" ; cout<<"["<<d2<<"] "; if(mom1>0){ mom1--; health2--; } if(mom2>0){ mom2--; health1--; } if(d1==5&&d2==5){ power1--; power2--; cout<<"大加血!"; health1+=2; health2+=2; } if((d1==5&&d2==2)||(d1==5&&d2==3)){ power1-=1; health1+=2; if(d2==3)power2++; cout<<"补血成功!"; } if((d1==2&&d2==5)||(d1==3&&d2==5)){ power2--; health2+=2; if(d1==3)power1++; cout<<"补血成功!"; } if(d1==5&&d2==1){ power1--; cout<<"打断补血"; } if(d1==5&&d2==4){ power1--; cout<<"打断补血"; } if(d2==5&&d1==1){ power2--; cout<<"打断补血"; } if(d1==4&&d2==5){ power2--; cout<<"打断补血"; } if (d1 == 1 && d2 == 1){ cout << "两人同时攻击,相安无事"; } if (d1 == 1 && d2 == 2){ power2++; health1--; cout << "武将2反弹了武将1的攻击,得1气"; } if (d1 == 2 && d2 == 1){ power1++; health2--; cout << "武将1反弹了武将2的攻击,得1气"; } if (d1 == 2 && d2 == 2){ cout << "两人同时防御,相安无事"; } if (d1 == 1 && d2 == 3){ health2--; cout << "武将2集气时受到武将1的攻击,损失1生命"; } if (d1 == 3 && d2 == 1){ health1--; cout << "武将1集气时受到武将2的攻击,损失1生命"; } if (d1 == 2 && d2 == 3){ power2++; cout << "武将2趁武将1防御时集气,得1气"; } if (d1 == 3 && d2 == 2){ power1++; cout << "武将1趁武将2防御时集气,得1气"; } if (d1 == 3 && d2 == 3){ power1++; power2++; cout << "双方同时集气,各得1气"; } if (d1 == 0 && d2 != 0&&d2 != 8){ power1 -= 2; health2 -= 3; cout << "武将1使出必杀,对对手造成3伤害"; } if (d1 != 0 && d2 == 0 && d1!=8){ power2 -= 2; health1 -= 3; cout << "武将2使出必杀,对对手造成3伤害"; } if (d1 == 0 && d2 == 0){ power1 -= 2; power2 -= 2; cout << "双方同时必杀,相安无事"; } if(d1==7&&d2!=8){ health2-=7; power1-=4; } if(d2==7&&d1!=8){ health1-=7; power2-=4; } if(d1==7&&d2==7){ cout<<"晴天"; } if(d1 == 6 && health2<=2 && mmm >0 && d2!=8){ health2-=1; mmm-=1; cout<<"最后终结!"; } if(d1==6 && health2>2){ cout << "【【【武将1不能来终结!重新开始回合" << cnt << "!】】】" << endl; return true; } if( d1==4 && d2==4){ cout<<"同时劫气"; } if(d1 ==4&&d2==2){ cout<<"劫气失败,反弹"; health1--; power2++; } if(d2 ==4&&d1==2){ cout<<"劫气失败,反弹"; power1++; health2--; } if(d1 ==4&&d2==1){ cout<<"劫气失败"; health1--; } if(d1 ==4&&d2==3){ cout<<"劫气大成"; power1++; power2--; } if(d2 ==4&&d1==1){ cout<<"劫气失败"; health2--; } if(d2 ==4&&d1==3){ cout<<"劫气大成"; power2++; power1--; } if(d1==8) { power1-=2; if(d2==2)cout<<"防御无效"; if(d2==3) { cout<<"防御无效"; power2++; } if(d2==8) { cout<<"大浪费"; power2-=2; } if(d2==1) { cout<<"反弹"; health2-=1; power1++; } if(d2==4) { power1++; cout<<"反弹"; health2--; } if(d2==5) { power2--; health2+=2; } if(d2==0||d2==7) { cout<<"防御!"; if(d2==0){ cout<<"反弹"; health2-=3; power2-=2; } if(d2==7)power2-=4; } } if(d2==8) { power2-=2; if(d1==2)cout<<"防御无效"; if(d1==3) { cout<<"防御无效"; power1++; } if(d1==8) { cout<<"大浪费"; power1-=2; } if(d1==1) { cout<<"反弹"; health1-=1; power2++; } if(d1==4) { power2++; cout<<"反弹"; health1--; } if(d1==5) { power1--; health1+=2; } if(d1==0||d1==7) { cout<<"防御!"; if(d1==0){ cout<<"反弹"; health1-=3; power1-=2; } if(d1==7)power1-=4; } } cout << "】】】" << endl; ++kk; if(power1<0)power1=0; if(power2<0)power2=0; if(health1>15)health1=15; if(health2>15)health2=15; return false;
}
//片段6 本回合战后统计 void result() {
cout << "【双方状态】" << endl; cout << "*武将1: 生命" << health1 << " 气" << power1 << endl; cout << "*武将2: 生命" << health2 << " 气" << power2 << endl << endl;
}//片段7 公布对战结果, winner == 1 代表武将1胜, winner == 2 代表武将2胜 void showWinner(int winner) { cout << endl << "【单挑结束!!!!!】" << endl; if (winner == 1) cout << "武将1战胜卢轩轩获胜!!!!" << endl; else cout << "武将2击败对手获胜!!!!" << endl; cout << endl << endl; } int ppp(int x,int y,int z,int w) {
if(z==1) { int Q=x*3+y+1; while(Q>60) Q-=10; return Q; } if(z==0) { int P=100-x-y+2*w; if(P>100)P=100; return P; }
} //片段2 进行游戏 int pk() { int cnt = 0; while (true) { // 一方倒下游戏结束 if (health1 <= 0) return 2; if (health2 <= 0) return 1;
cout << "【开始回合" << ++cnt << "】" << endl; if(u==5) { cout<<"神的佑护已发下"<<endl; ooo++; } // 片段3 确定人类策略, int human = human::strategy(); // 片段4 确定电脑策略 int ai = ai::strategy(); if(u==5&&y==0)human=8; if(u==5&&y==1)ai=8; if(u==5&&y==0) { power1+=2; cout<<"保佑你"<<endl; } if(u==5&&y==1) { cout<<"保佑对方"<<endl; power2+=2; } //片段5 对战 bool err = fight(human, ai); //片段6 本回合战后统计 if (!err) result(); else cnt--; }
}
int main() {
//片段1 游戏介绍 intro();//片段2 进行游戏 int winner = pk(); //片段7 公布对战结果 showWinner(winner); if(health1<1)qqqq=1; if(health2<1)qqqq=0; int QQ=ppp(kk,ooo,qqqq,health1); cout<<QQ<<"分"<<endl; if(QQ>=86&&QQ<90) { cout<<"A"<<endl; cout<<"晋级"<<endl; // cout<<"无赠送技能"; } if(QQ>=90&&QQ<95) { cout<<"S"<<endl; cout<<"晋级"<<endl; srand(time(0)); int yt=rand()%2 + 1; // if(yt==0)cout<<"赠送血量卡‘7’"; // else cout<<"赠送战斗卡‘-6’"; } if(QQ>=95&&QQ<98) { cout<<"SS"<<endl; cout<<"晋级"<<endl; srand(time(0)); int yt=rand()%2 + 1; // if(yt==0)cout<<"赠送血量卡‘8’"; // else cout<<"赠送战斗卡‘-8’"; } if(QQ>=98&&QQ<100) { cout<<"SSS"<<endl; cout<<"晋级"<<endl; srand(time(0)); int yt=rand()%2 + 1; // if(yt==0)cout<<"赠送血量卡‘9’"; // else cout<<"赠送战斗卡‘-9’"; } if(QQ==100) { cout<<"SSS+"<<endl; cout<<"晋级"<<endl; srand(time(0)); int yt=rand()%2 + 1; // if(yt==0)cout<<"赠送血量卡‘100’"<<endl; // else cout<<"赠送战斗卡‘-100’"<<endl; } if(QQ<86) { cout<<"已结束"; return 0; } // 游戏介绍 // 游戏环节 // 结果 return 0;
}</u>
-
Recent Activities