主要功能介绍:扑克牌共54张,但便于平均分配,所以就排除大小王,剩下52张,每人13张。
使这些牌随机分配给4个玩家player1-4、 以及给出牌的花色及大小、
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
//初始化扑克牌列表,使52张扑克牌均为未发状态
int puker[52]={0};
int main()
{
int cnt,p;
int send[52] = {0},i;
int player1[13] = {0};
int player2[13] = {0};
int player3[13] = {0};
int player4[13] = {0};
//设定随机化种子
srand(time(NULL));
//通过循环发牌
for(cnt = 0;cnt<52;)
{
p = rand()%52; //产生一个0-52之间的数
if(puker[p]==0)
{
puker[p] = 1;
send[i++]=p;
cnt++;
}
}
//测试发牌是否成功
// for(i=0;i<52;i++)printf("%d->%d\n",i,send[i]);
//将牌发给四个游戏玩家
for(cnt = 0,i = 0;cnt<52;)
{
player1[i] = send[cnt++];
player2[i] = send[cnt++];
player3[i] = send[cnt++];
player4[i] = send[cnt++];
i++;
}
//分别打印四个玩家的牌
//第一个玩家
for(i=0;i<13;i++)
{
printf("player1:第A%i张牌(%d)->",i,player1[i]);
if(player1[i]/13 == 0)printf("红桃");
else if(player1[i]/13 == 1)printf("方块");
else if(player1[i]/13 == 2)printf("梅花");
else if(player1[i]/13 == 3)printf("黑桃");
if(player1[i]%13 == 11)printf("J");
else if(player1[i]%13 == 12)printf("Q");
else if(player1[i]%13 == 0)printf("K");
else if(player1[i]%13 == 1)printf("A");
else printf("%d",player1[i]%13);
printf("\n");
}
printf("\n");
//第二个玩家
for(i = 0;i<13;i++)
{
printf("player1:第A%i张牌(%d)->",i,player2[i]);
if(player2[i]/13 == 0)printf("红桃");
else if(player2[i]/13 == 1)printf("方块");
else if(player2[i]/13 == 2)printf("梅花");
else if(player2[i]/13 == 3)printf("黑桃");
if(player2[i]%13 == 11)printf("J");
else if(player2[i]%13 == 12)printf("Q");
else if(player2[i]%13 == 0)printf("K");
else if(player2[i]%13 == 1)printf("A");
else printf("%d",player2[i]%13);
printf("\n");
}
printf("\n");
//第三个玩家
for(i = 0;i<13;i++)
{
printf("player3:第A%i张牌(%d)->",i,player3[i]);
if(player3[i]/13 == 0)printf("红桃");
else if(player3[i]/13 == 1)printf("方块");
else if(player3[i]/13 == 2)printf("梅花");
else if(player3[i]/13 == 3)printf("黑桃");
if(player3[i]%13 == 11)printf("J");
else if(player3[i]%13 == 12)printf("Q");
else if(player3[i]%13 == 0)printf("K");
else if(player3[i]%13 == 1)printf("A");
else printf("%d",player3[i]%13);
printf("\n");
}
printf("\n");
//第四个玩家
for(i = 0;i<13;i++)
{
printf("player4:第A%i张牌(%d)->",i,player4[i]);
if(player4[i]/13 == 0)printf("红桃");
else if(player4[i]/13 == 1)printf("方块");
else if(player4[i]/13 == 2)printf("梅花");
else if(player4[i]/13 == 3)printf("黑桃");
if(player4[i]%13 == 11)printf("J");
else if(player4[i]%13 == 12)printf("Q");
else if(player4[i]%13 == 0)printf("K");
else if(player4[i]%13 == 1)printf("A");
else printf("%d",player4[i]%13);
printf("\n");
}
printf("\n");
}