#include<bits/stdc++.h>
using namespace std;
int lom=0,wom=0,som=0;
int fx=1;
int xyxbz(){
som++;
int d=0,d1=0,x=1,x1=1,fs=0,fs1=0,shhzd=0;
char a;
while(x==1&&x1==1)
{
int mmm=rand()%3;
shhzd=d;
int shhjq=d1;
int f=0,f1=0,kh=0,kh1=0;
cout<<"请输入您的操作(A为装弹,B为开火,C为防御,D为大招):";
cin>>a;
cout<<endl;
if(a=='A')
{
d+=1;
fs=0;
}
else if(a=='B')
{
if(d>0){
d--;
kh=1;
fs=0;
}
else
cout<<"操作不合法!您此次行动机会被剥夺!";
}
else if(a=='C'&&fs<=10)
{
f=1;
fs++;
}
else if(a=='C'&&fs>10)
{
cout<<"防守次数超过上限!您此次行动机会被剥夺!"<<endl;
}
else if(a=='D'&&d>=5)
{
cout<<"你用大招秒杀了机器人,PLAYER IS WINNER!"<<endl;
wom++;
return 0;
}
if(d1>0&&d==4)
{
kh1=1;
fs1=0;
d1--;
cout<<"机器人选择开火"<<endl;
continue;
}
if(d1==0)
{
int s=0;
s++;
if(s==1)
d1++;
fs1=0;
}
else if(shhjq==5)
{
lom++;
cout<<"机器人用大招秒杀了你,COMPUTER IS WINNER!"<<endl<<"YOU LOSE!"<<endl;
return 0;
}
else if(shhzd==0)
{
d1++;
fs1=0;
cout<<"机器人选择装弹"<<endl;
}
else if(mmm==1&&d1>0)
{
kh1=1;
fs1=0;
d1--;
cout<<"机器人选择开火"<<endl;
}
else if(mmm!=1)
{
if(fs<=10)
{
f1=1;
fs1++;
cout<<"机器人选择防守"<<endl;
}
else {
int mm;
mm=rand()%5;
if(mm==1||mm==2||mm==3)
{
fs1=0;
kh1=1;
d1--;
cout<<"机器人选择开火"<<endl;
}
else
{
d1++;
cout<<"机器人选择装弹"<<endl;
}
}
}
if(kh1==1&&kh==1)
{
cout<<"啪!你俩的子弹相撞了!"<<endl;
}
else if(f1==1&&f==1)
{
cout<<"你们俩过于稳重"<<endl;
}
else if(kh==1&&f1==0)
{
wom++;
cout<<"你击毙了机器人,你赢了"<<endl;
return 0;
}
else if(kh1==1&&f==0)
{
lom++;
cout<<"你被机器人击毙了,你输了"<<endl;
return 0;
}
else cout<<"游戏继续"<<endl;
cout<<"目前您还剩"<<d<<"发子弹,"<<"累积连续防守次数为"<<fs<<endl;
cout<<"目前机器人还剩"<<d1<<"发子弹,"<<"累积连续防守次数为"<<fs1<<endl;
}
}
int main(){
srand(time(0));
char jx;
cout<<"欢迎游玩,本游戏为作者班里流行的一种小游戏,规则如下(行动不合法将剥夺一次行动机会)"<<endl;
cout<<"您可以选择装弹,开火,防守(不可超过十次)和大招(消耗5发子弹,秒杀对手)"<<endl;
int x=1;
while(x==1)
{
xyxbz();
cout<<"本局游戏结束,您当前的胜率是:"<<fixed<<setprecision(2)<<(float)wom/(float)som*100<<"%,"<<"您一共玩了"<<som<<"局,获胜"<<wom<<"场,失败"<<lom<<"场"<<endl;
cout<<"您还要继续游玩吗?(Y为继续,输入为其他立刻退出)";
cin>>jx;
cout<<endl;
if(jx=='Y')
x=1;
else
{
x=0;
cout<<"欢迎您下次游玩,再见!"<<endl;
}
}
system("pause");
return 0;
}
原创小游戏(前一篇修改版)
最新推荐文章于 2024-10-31 18:26:46 发布