正文

简单模拟发扑克牌(c代码)2006-03-19 22:33:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/vfdff/11182.html

分享到:

/*仅输出一位玩家的牌*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>

int puke[52]={0};
void input(int x,int y);

void xipai(void)
{
    int i=0,j=0,flag=0;
    int x=0,y=0,z=0;

    randomize();
    for(i=0;i<52;i++)
    {
        do{
            flag=0;
            x=(int)(rand()%4)+1;
            y=(int)(rand()%13)+1;
            z=x*100+y;
            for(j=0;j<i;j++)
            {
                if(puke[j]==z)
                {
                    flag=1;
                    break;
                }
            }
            if(flag==0)
            {
                puke[i]=z;
            }
        }while(flag);
    }
}

void fapai(void)
{
    int arr[13]={0};
    int i=0,j=0,k=0;
    int t=0,temp=0;
    int a=0,b=0;

    for(i=0;i<52;i++)
    {
        if(i%4==0)
        {
            arr[j]=puke[i];
            j++;
        }
    }
    for(j=1;j<12;j++)
    {
        t=13-j;
        for(k=0;k<t;k++)
        {
            if(arr[k]>arr[k+1])
            {
                temp=arr[k];
                arr[k]=arr[k+1];
                arr[k+1]=temp;
            }
        }
    }
    for(k=0;k<13;k++)
    {
        a=arr[k]/100;
        b=(((arr[k]/10)%10)*10)+arr[k]%10;
        input(a,b);
    }
}
void input(int x,int y)
{
    switch(x)
    {
        case 1:
            printf("H");
            break;
        case 2:
            printf("D");
            break;
        case 3:
            printf("C");
            break;
        case 4:
            printf("S");
            break;
    }
    switch(y)
    {
        case 1:
            printf("2 ");
            break;
        case 2:
            printf("3 ");
            break;
        case 3:
            printf("4 ");
            break;
        case 4:
            printf("5 ");
            break;
        case 5:
            printf("6 ");
            break;
        case 6:
            printf("7 ");
            break;
        case 7:
            printf("8 ");
            break;
        case 8:
            printf("9 ");
            break;
        case 9:
            printf("10 ");
            break;
        case 10:
            printf("J ");
            break;
        case 11:
            printf("Q ");
            break;
        case 12:
            printf("K ");
            break;
        case 13:
            printf("A ");
    }
}
int main(void)
{
    int i;
    clrscr();
    xipai();
    printf("\n\n\n\t");
    fapai();
    getch();
    return 0;
}
 
http://www.programfan.com/blog/article.asp?id=50
 

阅读(3268) | 评论(1)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

loading...
您需要登录后才能评论,请 登录 或者 注册