#include<bits/stdc++.h>
using namespace std;
int som=0,wom=0,lom=0;
int dqdz(){
srand(time(0));
char m,mp;
int db=0,df=0,j;
int s=5;
int mz=0,ml=0,mr=0;
som++;
for(int i=1;i<=s;i++)
{
if(db+s-i<df)
{
cout<<"机器人获胜!";
lom++;
return 0;
}
else if(df+s-i<db)
{
cout<<"玩家获胜!";
wom++;
return 0;
}
cout<<"输入L向左罚,输入R向右罚,输入M向中间罚"<<endl;
cin>>m;
if(m!='L'&&m!='R'&&m!='M')
{
cout<<"操作不合法,请重来一次"<<endl;
s++;
continue;
}
int jp=rand()%3+1;
if(jp==1)
{
cout<<"机器人扑向了左边"<<endl;
if(m=='L')
{
int ss=rand()%5;
if(ss!=1)
cout<<"很遗憾,您的点球被扑出"<<endl;
else
{
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else {
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else if(jp==2)
{
cout<<"机器人扑向了中间"<<endl;
if(m=='M')
{
int ss=rand()%5;
if(ss!=1)
cout<<"很遗憾,您的点球被扑出"<<endl;
else
{
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else {
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else if(jp==3)
{
cout<<"机器人扑向了右边"<<endl;
if(m=='R')
{
int ss=rand()%5;
if(ss!=1)
cout<<"很遗憾,您的点球被扑出"<<endl;
else
{
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else {
cout<<"您罚进了点球!"<<endl;
db++;
}
}
//JIQISFHMX
j=rand()%3+1;
cout<<"您要往哪边扑?(输入L向左扑,输入R向右扑,输入M站着不动)"<<endl;
cin>>mp;
if(j==1)
{
cout<<"机器人选择往左罚"<<endl;
if(mp=='L')
{
int sss=rand()%5;
if(sss!=1)
{
cout<<"恭喜您扑出点球!"<<endl;
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
if(j==2)
{
cout<<"机器人选择往中间罚"<<endl;
if(mp=='M')
{
int sss=rand()%5;
if(sss!=1)
{
cout<<"恭喜您扑出点球!"<<endl;
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
if(j==3)
{
cout<<"机器人选择往右罚"<<endl;
if(mp=='R')
{
int sss=rand()%5;
if(sss!=1)
{
cout<<"恭喜您扑出点球!"<<endl;
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
cout<<"当前总比分:您"<<db<<":"<<df<<"机器人"<<endl;
}
while(db==df)
{
cout<<"输入L向左罚,输入R向右罚,输入M向中间罚"<<endl;
cin>>m;
if(m!='L'&&m!='R'&&m!='M')
{
cout<<"操作不合法,请重来一次"<<endl;
s++;
continue;
}
int jp=rand()%3+1;
if(jp==1)
{
cout<<"机器人扑向了左边"<<endl;
if(m=='L')
{
int ss=rand()%5;
if(ss!=1)
cout<<"很遗憾,您的点球被扑出"<<endl;
else
{
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else {
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else if(jp==2)
{
cout<<"机器人扑向了中间"<<endl;
if(m=='M')
{
int ss=rand()%5;
if(ss!=1)
cout<<"很遗憾,您的点球被扑出"<<endl;
else
{
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else {
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else if(jp==3)
{
cout<<"机器人扑向了右边"<<endl;
if(m=='R')
{
int ss=rand()%5;
if(ss!=1)
cout<<"很遗憾,您的点球被扑出"<<endl;
else
{
cout<<"您罚进了点球!"<<endl;
db++;
}
}
else {
cout<<"您罚进了点球!"<<endl;
db++;
}
}
j=rand()%3+1;
cout<<"您要往哪边扑?(输入L向左扑,输入R向右扑,输入M站着不动)"<<endl;
cin>>mp;
if(j==1)
{
cout<<"机器人选择往左罚"<<endl;
if(mp=='L')
{
int sss=rand()%5;
if(sss!=1)
{
cout<<"恭喜您扑出点球!"<<endl;
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
if(j==2)
{
cout<<"机器人选择往中间罚"<<endl;
if(mp=='M')
{
int sss=rand()%5;
if(sss!=1)
{
cout<<"恭喜您扑出点球!"<<endl;
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
if(j==3)
{
cout<<"机器人选择往右罚"<<endl;
if(mp=='R')
{
int sss=rand()%5;
if(sss!=1)
{
cout<<"恭喜您扑出点球!"<<endl;
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
else {
cout<<"机器人罚进了点球!"<<endl;
df++;
}
}
cout<<"当前总比分:您"<<db<<":"<<df<<"机器人"<<endl;
}
if(db>df)
{
cout<<"玩家获胜!";
wom++;
}
else {
cout<<"电脑获胜!";
lom++;
}
return 0;
}
int main()
{
char jx;
cout<<"欢迎使用点球大战模拟器,祝您玩的开心"<<endl;
int x=1;
while(x==1)
{
dqdz();
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;
}
标签:cout,int,点球,srand,som,PVC,mp,&&,模拟器
From: https://blog.csdn.net/Oliver_Kahn/article/details/139456057