📄 三个数相加游戏2.cpp
字号:
#include "head.h"
void func2()
{system("cls");
char q;
int t=1;
j:cout<<"Do you want to start this game? Y/N ?"<<endl;//进入游戏
q=getchar();
system("cls");
if(q=='Y'||q=='y')
{cout<<'\t'<<"Welcome to the game!"<<endl<<endl;
cout<<"New game..1"<<endl;
int Money=1000,m;
cout<<'\t'<<"You get $1000 at the beignning."<<endl<<endl;
r:do
{cout<<"Please bet(at least $100):"<<'\t'<<'\t'<<'\t'<<"$";
cin>>m;
}
while(m<100||m>Money);
int a,p1=0;//p1的牌
srand(time(0));
{cout<<"p1:"<<'\t';
for(int n=1;n<=3;n++)
{
{do a=rand();
while (a<1||a>13);
}
cout<<a<<'\t';
{if(a>10)
a=10;
}
p1+=a;
}
cout<<"total:"<<'\t'<<p1<<endl;
}
for(int i=0;i<2;i++)//p1再拿牌
{if(p1<21)
{l:cout<<endl;
cout<<"Do you need one more card? Y/N?"<<endl;
q=getchar();
{if(q=='Y'||q=='y')
{do a=rand();
while (a<1||a>13);
if(a>10)
a=10;
p1+=a;
cout<<"p1:"<<'\t'<<a<<'\t'<<'\t'<<'\t'<<"total:"<<'\t'<<p1<<endl;
}
else {if(q=='N'||q=='n')
goto k;
else
goto l;}
}}}
cout<<endl;
k:int b,cpu=0;//cpu的牌
{cout<<"cpu:"<<'\t';
for(int n=1;n<=3;n++)
{
{do b=rand();
while (b<1||b>13);
}
cout<<b<<'\t';
{if(b>=11)
b=10;
}
cpu+=b;
}
cout<<"total:"<<'\t'<<cpu<<endl;
}
for(i=0;i<2;i++)//cpu再拿牌
{if((cpu<18&&i<2)&&a>b)
{do b=rand();
while (b<1||b>13);
if(b>10)
b=10;
cpu+=b;
cout<<"cpu:"<<'\t'<<a<<'\t'<<'\t'<<'\t'<<"total:"<<'\t'<<cpu<<endl;}
}
if((p1>cpu&&p1<21)||(cpu>21&&p1<21))//胜负条件
{Money+=m;
cout<<"You win!"<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"Money=$"<<Money<<endl;}
else{if(p1==21&&cpu!=21)
{Money+=(m*2);
cout<<"You win!"<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"Money=$"<<Money<<endl;}
else{if(cpu==21)
{Money-=(m*2);
if(Money<0)
Money=0;
cout<<"You lost!"<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"Money=$"<<Money<<endl;}
else{if(p1=cpu||(p1<cpu&&cpu<21))
{Money-=m;
if(Money<0)
Money=0;
cout<<"You lost!"<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"Money=$"<<Money<<endl;}
else {Money-=m;
if(Money<0)
Money=0;
cout<<"You lost!"<<'\t'<<'\t'<<'\t'<<'\t'<<'\t'<<"Money=$"<<Money<<endl;}
}
}
}
cout<<endl;cout<<endl;
if(Money>=100)//断续游戏
{kk:cout<<'\t'<<"Do you want to continue? Y/N?"<<endl;
q=getchar();
cout<<endl;
if(q=='Y'||q=='y')
{system("cls");
t++;
cout<<"New game.."<<t<<endl;
goto r;}
else{if(q=='N'||q=='n')
goto ll;
else
goto kk;}
}
else
cout<<"Sorry! You have not enough money!"<<endl;
goto ll;
}
else{if(q=='N'||q=='n')
ll: cout<<"Bye Bye!"<<endl;
else
goto j;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -