#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 dqdzsr()
{
char a,b;
int db=0,df=0;
cout<<"请双方玩家准备(输入L为左,M即为中间,R为右边,扑救时同理),";
for(int i=1;i<=5;i++)
{
if(db+5-i<df)
{
cout<<"player 2 is winner!";
return 0;
}
if(df+5-i<db)
{
cout<<"player 1 is winner!";
return 0;
}
cout<<"玩家1行动(您要往哪边射):"<<endl;
cin>>a;
cout<<"玩家2,您想往哪边扑"<<endl;
cin>>b;
if(a=='L')
cout<<"玩家1选择向左罚"<<endl;
else if(a=='M')
cout<<"玩家1选择向中间罚"<<endl;
else if(a=='R')
cout<<"玩家1选择向右罚"<<endl;
if(b=='R')
cout<<"玩家2选择向右扑"<<endl;
else if(b=='M')
cout<<"玩家2选择向中间扑"<<endl;
else if(b=='L')
cout<<"玩家2选择向左扑"<<endl;
if(a==b)
{
cout<<"很遗憾,玩家1的点球被玩家2神勇扑出"<<endl;
}
else
{
cout<<"恭喜玩家1罚进点球!"<<endl;
db++;
}
cout<<"玩家2行动(您要往哪边射):"<<endl;
cin>>b;
cout<<"玩家1,您想往哪边扑"<<endl;
cin>>a;
if(a=='L')
cout<<"玩家2选择向左罚"<<endl;
else if(a=='M')
cout<<"玩家2选择向中间罚"<<endl;
else if(a=='R')
cout<<"玩家2选择向右罚"<<endl;
if(b=='R')
cout<<"玩家1选择向右扑"<<endl;
else if(b=='M')
cout<<"玩家1选择向中间扑"<<endl;
else if(b=='L')
cout<<"玩家1选择向左扑"<<endl;
if(a==b)
{
cout<<"很遗憾,玩家2的点球被玩家1神勇扑出"<<endl;
}
else
{
cout<<"恭喜玩家2罚进点球!"<<endl;
df++;
}
cout<<"当前比分:玩家1 "<<db<<":"<<df<<"玩家2"<<endl;
}
while(db==df)
{
cout<<"玩家1行动(您要往哪边射):"<<endl;
cin>>a;
cout<<"玩家2,您想往哪边扑"<<endl;
cin>>b;
if(a=='L')
cout<<"玩家1选择向左罚"<<endl;
else if(a=='M')
cout<<"玩家1选择向中间罚"<<endl;
else if(a=='R')
cout<<"玩家1选择向右罚"<<endl;
if(b=='R')
cout<<"玩家2选择向右扑"<<endl;
else if(b=='M')
cout<<"玩家2选择向中间扑"<<endl;
else if(b=='L')
cout<<"玩家2选择向左扑"<<endl;
if(a==b)
{
cout<<"很遗憾,玩家1的点球被玩家2神勇扑出"<<endl;
}
else
{
cout<<"恭喜玩家1罚进点球!"<<endl;
db++;
}
cout<<"玩家2行动(您要往哪边射):"<<endl;
cin>>b;
cout<<"玩家1,您想往哪边扑"<<endl;
cin>>a;
if(b=='L')
cout<<"玩家2选择向左罚"<<endl;
else if(b=='M')
cout<<"玩家2选择向中间罚"<<endl;
else if(b=='R')
cout<<"玩家2选择向右罚"<<endl;
if(a=='R')
cout<<"玩家1选择向右扑"<<endl;
else if(a=='M')
cout<<"玩家1选择向中间扑"<<endl;
else if(a=='L')
cout<<"玩家1选择向左扑"<<endl;
if(a==b)
{
cout<<"很遗憾,玩家2的点球被玩家1神勇扑出"<<endl;
}
else
{
cout<<"恭喜玩家2罚进点球!"<<endl;
df++;
}
cout<<"当前比分:玩家1 "<<db<<":"<<df<<"玩家2"<<endl;
}
if(db>df)
cout<<"player 1 is winner!"<<endl;
else cout<<"player 2 is winner!"<<endl;
return 0;
}
int main()
{
char jx;
int mod;
cout<<"欢迎使用点球大战模拟器,祝您玩的开心"<<endl;
int x=1;
while(x==1)
{
cout<<"请选择模式(1为PVC,2为PVP(不计入场次))"<<endl;
cin>>mod;
if(mod==1)
{
dqdz();
}
else if(mod==2)
{
dqdzsr();
cout<<"您还要继续游玩吗?(Y为继续,输入为其他立刻退出)";
cin>>jx;
cout<<endl;
if(jx=='Y')
x=1;
else
{
x=0;
cout<<"欢迎您下次游玩,再见!"<<endl;
}
continue;
}
else
{
cout<<"操作不合法!"<<endl;
continue;
}
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;
}
点球大战小游戏最终版(附PVP)
最新推荐文章于 2024-10-31 18:26:46 发布