C语言 21点游戏
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include
#include
#include
#include
#include
int Bookies_score=1000,/*庄家金币*/Rlayer_score=1000;//玩家金币
int Bookiesscore=0,/*庄家当前点数*/Rlayerscore=0;//玩家当前点数
int Random,/*玩家随机数*/Randoms;//庄家随机数
int Bets_P;//玩家下注
int Card;//是否发牌
int i=1;
int s=1;
int main(void)
{
Star_interface();//开始界面
getch();
system("CLS");
//---------------------------------以下为产生玩家随机数发牌代码
Judge_WorL();//输或者赢函数
}
//------------以下开始界面
int Star_interface()
{
int i;
system("color 9B");
printf("\t\t\t C语言游戏:二十一点\n");
printf("\n\n\n\n\n\n\n");
printf(" 〓〓〓〓〓〓〓 〓");
printf("\n 〓\n 〓〓〓〓〓〓〓 〓〓〓〓〓〓〓\n 〓\n 〓\n");
printf(" 〓〓〓〓〓〓〓 〓\n");
printf("\n\n");
printf("\t\t\t ①:查看规则 ②:开始游戏\n\n");
printf("\t\t\t 制作人:小二\n\n");
printf("\t\t\t 版本号:1.0\n\t\t\t");
scanf("%d",&i);
switch(i)
{
case 1:
system("CLS");
printf("\t\t\t 二十一点游戏规则\n\n\n\t 介绍:手中所有的牌点数之和不超过21点,谁更接近21点,就赢得游戏。\n\n ");
printf("\t\t\t ①:2 到 10 的牌的点数就是其牌面的数字.\n\n \t\t\t ②:J 、 Q 、 K 的点数是 10 分.\n\n\t\t\t ③:A 有两种算法,1或者11,如果 A 算为11时总和\n\n \t\t\t 大于21,则 A 算为1.\n\n\t\t\t ");
printf("④自己判断,只要不超过21,都可以再摸一张。\n\n\t\t\t ");
printf("⑤玩家点数超过21点(爆牌),则为输. 点数相等时,庄家赢.\n\n\t\t\t 点数大则大.\n");
getch();
break;
case 2:
break;
//default:
}
printf("\t\t\t\t按任意键开始游戏");
//---------------------------------以上为开始界面
//---------------------------------
}
int Game_interface()
{
printf("\t\t 庄家金币:%d 玩家金币:%d\n",Bookies_score,Rlayer_score);
printf("\t\t --------------------------------\n");
}
int Judge_C()
{
for(i;i<3;i++)
{
srand(time(0));
Random=rand()%(14-1+1)+1;//确定随机数范围为1-14.
while(Random==11){srand(time(0));Random=rand()%(14-1+1)+1;}
if(Random==1){NUM_A();if(Rlayerscore+11>21){Rlayerscore+=1;}else{Rlayerscore+=11;}}
if(Random==2){NUM_2();Rlayerscore+=2;}
if(Random==3){NUM_3();Rlayerscore+=3;}
if(Random==4){NUM_4();Rlayerscore+=4;}
if(Random==5){NUM_5();Rlayerscore+=5;}
if(Random==6){NUM_6();Rlayerscore+=6;}
if(Random==7){NUM_7();Rlayerscore+=7;}
if(Random==8){NUM_8();Rlayerscore+=8;}
if(Random==9){NUM_9();Rlayerscore+=9;}
if(Random==10){NUM_10();Rlayerscore+=
10;}
if(Random==12){NUM_J();Rlayerscore+=10;}
if(Random==13){NUM_Q();Rlayerscore+=10;}
if(Random==14){NUM_K();Rlayerscore+=10;}
//------------------------------------------以下为庄家判断
if(s==1)
{
Randoms=rand()%(14-1+1)+1;
while(Randoms==11){srand(time(0));Randoms=rand()%(14-1+1)+1;}
if(Randoms>10){Randoms=10;}
if(Randoms==1){if(Bookiesscore+11>21){Randoms=1;}else{Randoms=11;}}
Bookiesscore+=Randoms;
}
Sleep(1000);
}
i=1;
s++;
printf("\t\t\t 玩家当前%d点\n",Rlayerscore);
}
int Judeg_B()
{
Randoms=rand()%(14-1+1)+1;
while(Randoms==11){srand(time(0));Randoms=rand()%(14-1+1)+1;}
if(Randoms>10){Randoms=10;}
if(Randoms==1){if(Bookiesscore+11>21){Randoms=1;}else{Randoms=11;}}
Bookiesscore+=Randoms;
printf("\t\t\t玩家当前%d点 庄家当前%d点\n",Rlayerscore,Bookiesscore);
}
int Judge_WorL()
{
while(1)
{
Game_interface();//游戏界面
if(Rlayer_score==0){printf("\t\t\t 您已经没有金币了!\n \t\t\t 游戏结束!\n");break;}
if(Bookies_score<=0){printf("\t\t\t您真厉害,庄家已经没有金币了!\n \t\t\t 游戏结束!\n\n\n");break;}
printf("\t\t\t\t玩家下注:");
scanf("%d",&Bets_P);
while(Bets_P>Rlayer_score){printf("\t\t\t您下注金币超过当前金币数!请重新下注:");scanf("%d",&Bets_P);}
printf("\n\t\t\t 游戏开始,系统开始发牌\n");
while(1)
{
Judge_C();
i=2;
if(Rlayerscore>21)
{
printf("\n\n\n\t\t\t你的点数超过21点!你输了!");
Judge_M();
s=1;
break;
}
printf("\n\n 是否继续发牌? 1是/2否");
scanf("%d",&Card);
if(Card==1)
{
system("CLS");
Game_interface();
printf("\t\t\t\t玩家下注:%d\n",Bets_P);
}else{
Judeg_B();
if(Bookiesscore>21)
{
printf("\n\n\n\t\t\t庄家的点数超过21点!你赢了!");
Rlayer_score=Rlayer_score+Bets_P;
Bookies_score=Bookies_score-Bets_P;
Bookiesscore=0;
Rlayerscore=0;
s=1;
getch();
system("CLS");
i=1;
break;
}
if(Rlayerscore>Bookiesscore)
{
system("CLS");
printf("\n\n\n\t\t\t\t恭喜!你赢了!");
Rlayer_score=Rlayer_score+Bets_P;
Bookies_score=Bookies_score-Bets_P;
Bookiesscore=0;
Rlayerscore=0;
i=1;
s=1;
getch();
system("CLS");
break;
}else
{
if(Rlayerscore<=Bookiesscore)
{
printf("\n\n\n\t\t\t\t对不起,你输了!");
Judge_M();
s=1;
break;
}
}
}
}
}
}
int Judge_M()
{
Rlayer_score=Rlayer_score-Bets_P;
Bookies_score=Bookies_score+Bets_P;
Bookiesscore=0;
Rlayerscore=0;
i=1;
getch();
system("CLS");
}
//以下
为扑克牌图形绘制调用函数
int NUM_A(){
printf("┏━━━━━┓\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆◆◆ ┃\n");
printf("┃◆ ◆┃\n");
printf("┗━━━━━┛\n");
}
int NUM_2(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_3(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_4(){
printf("┏━━━━━┓\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆◆◆┃\n");
printf("┃ ◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_5(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_6(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_7(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_8(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_9(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_10(){
printf("┏━━━━━┓\n");
printf("┃ ◆ ◆◆◆┃\n");
printf("┃ ◆ ◆ ◆┃\n");
printf("┃ ◆ ◆ ◆┃\n");
printf("┃ ◆ ◆ ◆┃\n");
printf("┃ ◆ ◆◆◆┃\n");
printf("┗━━━━━┛\n");
}
int NUM_J(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆ ┃\n");
printf("┗━━━━━┛\n");
}
int NUM_Q(){
printf("┏━━━━━┓\n");
printf("┃ ◆◆
◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃◆ ◆┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆◆◆┃\n");
printf("┗━━━━━┛\n");
}
int NUM_K(){
printf("┏━━━━━┓\n");
printf("┃ ◆ ◆ ┃\n");
printf("┃ ◆◆ ┃\n");
printf("┃ ◆ ┃\n");
printf("┃ ◆◆ ┃\n");
printf("┃ ◆ ◆ ┃\n");
printf("┗━━━━━┛\n");
}