c++小游戏——职业战争

mac2022-06-30  107

#include<iostream> #include<cstdlib> #include<ctime> #include<cstring> #include<windows.h> using namespace std; int i,H[3],S[3],K[3],p=1,Y,C; string P[3]; bool game=1; void a(int i){ for (;i;i--); } void help(){ cout<<"杀手:\nHP:100\nSP:5\nkill:3\n"; cout<<"医生:\nHP:75\nSP:7\nkill:2\n"; cout<<"法师:\nHP:144\nSP:3\nkill:1\n"; cin>>i; } void killer(){ P[p]+="杀手"; H[p]=100; S[p]=5; K[p]=3; } void doctor(){ P[p]+="医生"; H[p]=75; S[p]=7; K[p]=2; } void engineer(){ P[p]+="法师"; H[p]=144; S[p]=3; K[p]=1; } void e(int j){ if (j==2&&S[Y]>=2) { int w=rand()%2; if (Y==1) cout<<"你使用奖励\n"; else cout<<"电脑使用奖励\n"; K[Y]+=w; cout<<"杀人数+"<<w<<endl; w=rand()%5-1; w=int(1.2*(K[Y]+w)); H[C]-=w; if (H[C]<=0) game=0; if (Y==1) cout<<"你杀了电脑 "; else cout<<"你被电脑杀了 "; cout<<w; if (Y==1) cout<<endl; S[Y]-=2; } } void k(int j){ if (j==2&&S[Y]>=2) { if (Y==1) cout<<"YOU 使用奖励\n"; else cout<<"The computer 使用奖励\n"; int w=rand()%4+1; H[C]-=int(1.5*K[Y]+w); if (H[C]<=0) game=0; if (Y==1) cout<<"杀 "; else cout<<"你被电脑杀了 "; cout<<int(1.5*K[Y]+w); if (Y==1) cout<<endl; S[Y]-=2; } } void d(int j){ if (j==2&&S[Y]>=2) { if (Y==1) cout<<"YOU 使用奖励\n"; else cout<<"The computer 使用奖励\n"; int w=rand()%5; H[Y]+=K[Y]+w; if (Y==1) cout<<"YOU HP+"; else cout<<"The computer HP+"; cout<<K[Y]+w; if (Y==1) cout<<endl; S[Y]-=2; } } void play(){ system("cls"); cout<<"Game start!!!!!!!!!!!!!!!!"; Sleep(3000); system("cls"); int r=1,j; // bool game=1; while (game){ Y=1; C=2; cout<<"Round "<<r<<"\n"; Sleep(3000); cout<<"The 电脑 HP:"<<H[2]<<" SP:"<<S[2]<<" kill:"<<K[2]<<"\t"<<P[2]; cout<<"\n\n\n\nYour HP:"<<H[1]<<" SP:"<<S[1]<<" kill:"<<K[1]<<"\t"<<P[1]; Sleep(3000); cout<<"\nYou choose:\n1.杀人(1SP)\n2.奖励(2SP)\n3.大杀特杀(5SP)\n4.啥事都没(+1~3SP)\n5.干哈(+0~2kill)\n6.尝试(3SP)"; cin>>j; if (j==1&&S[Y]>0) { int w=rand()%5-1; S[Y]--; H[C]-=K[Y]+w; if (H[C]<=0) game=0; cout<<"You kill the computer"<<K[Y]+w<<endl; } else { if (j==4) { int w=rand()%3+1; S[Y]+=w; cout<<"YOU SP+"<<w<<endl; } else { if (j==5) { int w=rand()%3; K[Y]+=w; cout<<"YOU kill+"<<w<<endl; } else { if (P[Y]=="killer") k(j); if (P[Y]=="doctor") d(j); if (P[Y]=="engineer") e(j); } } } if (game){ j=rand()%6+1; C=1; Y=2; while (j!=1&&j!=2&&j!=4&&j!=5) j=rand()%6+1; if (j==1&&S[2]>1) { int w=rand()%5-1; S[2]--; H[1]-=K[2]+w; if (H[1]<=0) game=0; cout<<"你被电脑杀了"<<K[2]+w; } else { if (j==4) { int w=rand()%3+1; S[2]+=w; cout<<"The computer SP+"<<w; } else { if (j==5) { int w=rand()%3; K[2]+=w; cout<<"The computer kill+"<<w; } else { if (P[Y]=="killer") k(j); if (P[Y]=="doctor") d(j); if (P[Y]=="engineer") e(j); } } } if (game) Sleep(3000); } r++; system("cls"); } } int main(){ srand((unsigned)time(NULL)); cout<<"Welcome to my game!!!!!!!!!!!!\n"; Sleep(3000); system("cls"); cout<<"Please choose:\n1.killer\n2.doctor\n3.engineer\n4.help"; cin>>i; if (i==4) help(); cout<<"You choose "; if (i==1) killer(); if (i==2) doctor(); if (i==3) engineer(); cout<<P[p]<<endl; i=rand()%3+1; p++; cout<<"The computer chooses "; if (i==1) killer(); if (i==2) doctor(); if (i==3) engineer(); cout<<P[p]<<endl; system("pause"); play(); if (H[1]<=0) cout<<"YOU LOSE~~~~~~~~~~~~~~~~~"; else cout<<"YOU WIN!!!!!!!!!!!!!!!!!!!"; return 0; }

转载于:https://www.cnblogs.com/vercont/p/10210102.html

相关资源:c 写的小游戏---大战黑帮
最新回复(0)