为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > 纸牌游戏:十点半

纸牌游戏:十点半

2023-03-17 3页 doc 1MB 2阅读

用户头像 个人认证

is_517709

暂无简介

举报
纸牌游戏:十点半纸牌游戏:十点半计算机技术基础课程设计C语言设计报告题目:纸牌游戏:十点半学院:化学工程学院专业:制药工程班级:050607班姓名:李艳明指导教师:设计日期:2007年1月10日不能再要牌。玩家牌的总点数一旦超过10.5,不能再要牌,J,Q,K算为半点。如果玩家牌的总点数都大于或小于10.5,点大者胜;如果有大于也有小于10.5,则点数最小者赢。(二)任何一张纸牌都有其本身的属性:花色,数值及起其所代表的点数。为将这些特征表示出来,特定义一个结构体数组来表示一副扑克牌,由于十点半游戏中不需要大小王,故可以定义如下:Struct...
纸牌游戏:十点半
纸牌游戏:十点半计算机技术基础课程设计C语言设计报告题目:纸牌游戏:十点半学院:化学工程学院专业:制药工程班级:050607班姓名:李艳明指导教师:设计日期:2007年1月10日不能再要牌。玩家牌的总点数一旦超过10.5,不能再要牌,J,Q,K算为半点。如果玩家牌的总点数都大于或小于10.5,点大者胜;如果有大于也有小于10.5,则点数最小者赢。(二)任何一张纸牌都有其本身的属性:花色,数值及起其所代的点数。为将这些特征表示出来,特定义一个结构体数组来表示一副扑克牌,由于十点半游戏中不需要大小王,故可以定义如下:Structbook{intcolor;charnumber;floatnum;}Card[52];(三)不论何种扑克游戏都有其必经的三个步骤:一是有一副牌(即牌的初始化)二是洗牌,三是发牌。这三个步骤在程序中通过三个函数来实现:voidBuild_Show(intHuaSe[],floatDianShu[],charShuZi[]);voidWash_Card(void);voidGet_Card(intn);三.流程图for调用函数do循环调用函数终止Main()函数流程图Build_Show()的流程图Wash_Card()的流程图forforRand1!=rand2产生rand1,rand2i<1000i=0j++j<13j=0fori<4i=0i++交换牌Card[j+13*i].color=HuaSe[i]Card[j+13*i].number=ShuZi[i]Card[j+13*i].num=DianShu[i]结束puts()i++fori=0,j=0j<52j%13==0\nprintf()结束Get_Card()的流程图DuoRen()的流程图调用函数调用函数if每个人都拿第一张牌n==4n==1当所有人都不能拿牌时结束循环人与电脑游戏并输出游戏结果调用函数Duo_Ren()公布结果,由各人的点数可知调用结束调用结束四。程序#defineN5#include#includestructbook{intcolor;charnumber;floatnum;}Card[52];/*Tostorethecolor,numberandthepoints*/voidBuild_Show(intHuaSe[],floatDianShu[],charShuZi[]);/*Establishapairofcardsandshowittotheplayer*/voidWash_Card(void);/*Washthecards*/voidGet_Card(intn);/*Givetheplayercardsandtheresult*/voidDuoRen();intmain(void){intflag,n;intHuaSe[4]={3,4,5,6};/*Storethecolor*/charShuZi[13]={'A','K','Q','J','0','9','8','7','6','5','4','3','2'};/*Storethenumber*/floatDianShu[13]={1,0.5,0.5,0.5,10,9,8,7,6,5,4,3,2};/*Storethepoints*/Build_Show(HuaSe,DianShu,ShuZi);/*Establishthecardandshowit*/do{Wash_Card();/*Washcards*/a:puts("\nPleaseinputthenumberoftheplayer:");scanf("%d",&n);switch(n){case1:puts("Youplaywiththecomputer!");break;case2:puts("Youtwoplay!");break;case3:puts("Youthreeplay!");break;case4:puts("Youfourplay!");break;case5:puts("Youfiveplay!");break;case6:puts("Yousixplay!");break;case7:puts("Yousevenplay!");break;case8:puts("Youeightplay!");break;default:puts("Thenumberoftheplayersistoolarge!");gotoa;}Get_Card(n);/*Handoutthecardsandgivetheresult*/do{puts("\nDoyouwanttoplayagain?1representsyesand0no:");scanf("%d",&flag);}while(flag!=1&&flag!=0);}while(flag==1);}voidBuild_Show(intHuaSe[],floatDianShu[],charShuZi[]){inti,j;for(i=0;i<4;i++)/*Establishapairofcards*/for(j=0;j<13;j++){Card[j+13*i].color=HuaSe[i];Card[j+13*i].number=ShuZi[j];Card[j+13*i].num=DianShu[j];}puts("Thisisanewpairofcards:");/*Showthewholepairtotheplayerstocheck*/for(i=0,j=0;i<52;i++,j++){if(!(j%13))printf("\n");printf("%c%c",Card[i].color,Card[i].number);}}voidWash_Card(void){inti,rand1,rand2,hua;chardian;floatshu;for(i=0;i<1;i++){rand1=random(52);/*Getacardbyrandom,andputthecardsintomess*/rand2=random(52);if(rand1!=rand2)hua=Card[rand1].color;Card[rand1].color=Card[rand2].color;Card[rand2].color=hua;dian=Card[rand1].number;Card[rand1].number=Card[rand2].number;Card[rand2].number=dian;shu=Card[rand1].num;Card[rand1].num=Card[rand2].num;Card[rand2].num=shu;}}voidGet_Card(intn)/*Handoutthecardsonebyoneandgivetheresult*/{inti=0,j=0,k=0,flag=1,flag2=1;floatsum_m=0,sum_c=0;structbookMan[52],Computer[52];if(n==1){while(flag==1&&i<52){Man[j++]=Card[i++];/*Mangetsthecardfirstly*/sum_m+=Man[j-1].num;/*Acumulatethewholepointsoftheman*/if(flag2==1&&i<52&&(sum_m<=10.5&&sum_c<=10.5&&(sum_c+Card[i].num)<=10.5||sum_m>10.5&&(sum_c+Card[i].num)>=sum_m))/*Letthecomputerknowwhatthenextcardisanddecidewhethertogetacard*/{Computer[k++]=Card[i++];/*Thecomputergetsacard*/sum_c+=Computer[k-1].num;/*Acumulatethewholepointsofthecomputer*/}elseflag2=0;printf("\n");puts("Nowthecardsyougetare:");for(i=0;i10.5&&(sum_c+Card[i].num)>=sum_m))/*Letthecomputerknonwswhatthenextcardisanddecidewhetertogetone*/{Computer[k++]=Card[i++];sum_c+=Computer[k-1].num;if(sum_c>10.5)break;}puts("Okay,nowgiveouttheresult:");puts("Nowthecardsyou'vegotare:");for(i=0;i10.5&&sum_c>10.5)||(sum_m<=10.5&&sum_c<=10.5))if(sum_m>sum_c)puts("Youwinthecomputer!It'sunbelievable!");elseif(sum_m==sum_c)puts("Youplayaswellasthecomputer,andyou'rereallygood.");elseputs("Thecomputerwinsandyouneedmorepractice!");elseif(sum_m<=10.5&&sum_c>10.5)puts("Youwinthecomputer!It'sunbelievable!");elseputs("Thecomputerwinsandyouneedmorepractice!");}elseDuoRen();}voidDuoRen(){structbookMan[N][52];inti,a[N]={0},k=0,flag[N],flag2=1,s=0,m=0;floatsum[N]={0},q,t;for(i=0;i10.5)flag[i]=0;}s=0;for(k=0;k
/
本文档为【纸牌游戏:十点半】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索