我非常接近完成这个,至少我希望如此,因为如果我不这样做,我会发疯的。我已经设法摆脱所有语法和错误以摆脱编译器,我开始它希望我最终会完成然后......它崩溃了......
为了大致了解它的工作原理,假设从“甲板”中打印出五个值 - 然后再次随机打乱打印(以显示打乱)
我是如此接近。我可以尝尝!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 52
enum faces{Ace = 0, Jack = 10, Queen, King};
char * facecheck(int d);
void shuffle( int deck[]);
void draw(int deck[SIZE]);
void cards(int hand);
int main()
{
int deck[SIZE], i, n;
char suits[4][9] =
{
"Hearts",
"Diamonds",
"Clubs",
"Spades"};
srand( time( NULL ) ) ;
for(i = 0; i<SIZE; i++)
{
deck[i] = i;
i++;
};
draw(deck);
shuffle(deck);
draw(deck);
return 0;
}
char * facecheck(int d)
{
static char * face[] =
{
"Ace",
"Jack",
"Queen",
"King" };
if(d == Ace)
return face[0];
else
{
if(d == Jack)
return face[1];
else
{
if(d == Queen)
return face[2];
else
{
if(d == King)
return face[3];
}
}
}
}
void shuffle( int deck[])
{
int i, j, temp;
for(i = 0; i < SIZE; i++)
{
j = rand() % SIZE;
temp = deck[i];
deck[i] = deck[j];
deck[j] = temp;
}
printf("The deck has been shuffled \n");
}
void draw(int deck[SIZE])
{
int i;
int hand[i];
for(i = 0; i < 5; i++)
{
cards(hand[i]);
putchar('\n');
}
}
void cards(hand)
{
int i;
char suits[4][9] =
{
"Hearts",
"Diamonds",
"Clubs",
"Spades"};
for(i=0; i<SIZE; i++)
{
if(i%13 == 0 || i%13 == 10 || i%13 == 11 || i%13 == 12)
printf("%s ", facecheck(i%13) );
else printf("%d ", i%13+1);
printf("of %s \n", suits[i/13]);
}
}