C语言实现洗牌与发牌游戏
本文实例为大家分享了C语言实现洗牌与发牌游戏的具体代码,供大家参考,具体内容如下
普通版
#include#include #include #defineSUITS4 #defineFACES13 #defineCARDS52 voidshuffle(intwDeck[][FACES]); voidsend(intwDeck[][FACES],constchar*wSuit[],constchar*wFace[]); voidmain() { intdeck[SUITS][FACES]={0}; constchar*suit[SUITS]={"Heart","Diamond","Club","Spade"}; constchar*face[FACES]={"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}; srand(time(NULL)); shuffle(deck); send(deck,suit,face); } voidshuffle(intwDeck[][FACES]) { introw,column,card; for(card=1;card<=CARDS;card++) { row=rand()%SUITS; column=rand()%FACES; while(wDeck[row][column]!=0) { row=rand()%SUITS; column=rand()%FACES; } wDeck[row][column]=card; } } voidsend(intwDeck[][FACES],constchar*wSuit[],constchar*wFace[]) { intcard,row,column; for(card=1;card<=CARDS;card++) { for(row=0;row 高性能版
//先按顺序填满52个格子,再产生随机格子相互交换 #include#include #include #defineCARDS52 #defineFACES13 structcard { constchar*face; constchar*suit; }; typedefstructcardCard; voidshuffle(Card*constwDeck); voidsend(constCard*constwDeck);//指针常量与数据常量均不可以改变,都用const限定,*前是限定指针,*后是限定数据 voidmain() { constchar*wSuit[]={"Heart","Diamond","Club","Spade"};//指针数组是一个数组 constchar*wFace[]={"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"}; inti; Carddeck[CARDS]; for(i=0;i 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。