当前位置:编程学习 > C/C++ >>

模拟发扑克牌程序

[cpp]
#include<stdio.h> 
#include <string.h> 
#include <stdlib.h> 
#include <time.h> 
 
 
struct CARD 

    char suit[10];//花色 
    char face[10];//牌面 
}; 
 
 
void Deal(struct CARD *wCard); 
void Shuffle(struct CARD *wCard); 
void FillCard(struct CARD wCard[],char *wFace[],char *wSuit[]); 
 
 
 
 
int main() 

    char *suit[]={"Spades","Hearts","Clubs","Diamonds"};//黑 红 梅花 方片 
    char *face[]={"A","2","3","4","5","6","7","8","9","10","Jack","Queen","King"}; 
    //int i; 
    struct CARD card[52]; 
     
    srand(time(NULL)); 
    FillCard(card,face,suit); 
    Shuffle(card); 
    Deal(card); 

 
 
//洗牌过程 
void FillCard(struct CARD wCard[],char *wFace[],char *wSuit[]) 

    int i; 
 
 
    for (i=0;i<52;i++) 
    { 
        strcpy(wCard[i].suit,wSuit[i/13]); 
        strcpy(wCard[i].face,wFace[i%13]); 
    } 

 
 
//发牌过程 
void Shuffle(struct CARD *wCard) 

    int i,j; 
    struct CARD temp; 
 
 
    for (i=0;i<52;i++) 
    { 
        j=rand()%52; 
        temp=wCard[i]; 
        wCard[i]=wCard[j]; 
        wCard[j]=temp; 
    } 

 
 
//输出发牌结果 
void Deal(struct CARD *wCard) 

    int i; 
     
    for (i=0;i<52;i++) 
    { 
        printf("%2d:%10s%10s\n",i+1,wCard[i].suit,wCard[i].face); 
    } 

 

补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,