Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- #define SIZE 36
- #define HAND_SIZE 6
- #define LEAR_LIST 4
- #define MAX 14
- typedef struct
- {
- int par;
- char lear;
- }card;
- void create_deck(card deck[]);
- void take_card(card deck[], card hand[]);
- void print_hand (card hand[]);
- int main(void)
- {
- system( "chcp UTF-16" );
- system ("cls");
- card deck[SIZE]={0};
- card hand[HAND_SIZE]={0};
- create_deck(deck);
- take_card(deck, hand);
- print_hand(hand);
- return 0;
- }
- void create_deck(card deck[])
- {
- int temp_index=0;
- for(int i=0;i<LEAR_LIST;i++)
- {
- for(int j=6;j<=MAX;j++)
- {
- deck[temp_index].par=j;
- deck[temp_index].lear=65+i;
- temp_index++;
- }
- }
- }
- void take_card(card deck[], card hand[])
- {
- time_t tm;
- int t=time(&tm);
- srand(tm);
- int index=0;
- for(int i=0;i<HAND_SIZE;i++)
- {
- index=rand()%(SIZE-1);
- hand[i]=deck[index];
- }
- }
- void print_hand (card hand[])
- {
- for(int i=0;i<HAND_SIZE;i++)
- {
- switch (hand[i].par)
- {
- case 11:
- printf("J"); break;
- case 12:
- printf("D"); break;
- case 13:
- printf("K"); break;
- case 14:
- printf("A"); break;
- default:
- printf("%d", hand[i].par);
- break;
- }
- switch (hand[i].lear)
- {
- case 65:
- printf("\x06"); break; //SPADE
- case 66:
- printf("\x05"); break; //CLUB
- case 67:
- printf("\x03"); break; //HEART
- case 68:
- printf("\x04"); break; //DIAMOND
- default:
- break;
- }
- printf (" ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement