Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.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[], int *curr);
- void print_hand (card hand[]);
- void welcome();
- int main(void)
- {
- system ("chcp 65001");
- system ("cls");
- system ("color F0");
- int curr=0;
- char ch=0;
- card deck[SIZE]={0};
- card hand[HAND_SIZE]={0};
- create_deck(deck);
- welcome();
- printf("Press 'y'\n");
- while(1)
- {
- ch=_getch();
- if(ch=='y')
- {
- take_card(deck, hand, &curr);
- print_hand(hand);
- printf("\nTake one more card?(y/n): \n");
- }
- else if(ch=='n')
- {
- system("cls");
- printf("=)");
- break;
- }
- }
- _getch();
- 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[], int *curr)
- {
- time_t tm;
- int t=time(&tm);
- srand(t);
- int index=rand()%(SIZE-1);;
- while(1)
- {
- if(deck[index].par==0 && deck[index].lear=='0')
- {
- index=rand()%(SIZE-1);
- }
- else
- {
- hand[*curr]=deck[index];
- deck[index].par=0;
- deck[index].lear='0';
- break;
- }
- }
- }
- void print_hand (card hand[])
- {
- for(int i=0;i<HAND_SIZE;i++)
- {
- if(hand[i].par==0) break;
- 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 (" ");
- }
- }
- void welcome()
- {
- printf("-----------------------------------------------\n");
- printf("| Black Jack Game |\n");
- printf("-----------------------------------------------\n");
- printf("Press any key to read rules...\n");
- _getch();
- system("cls");
- printf("Rules: \n\n");
- printf(" You must collect a combination of cards as close as possible to 21.\n \
- If you go over, you lose.\n \
- To win - the sum of your cards must be higher than the sum of the dealer's cards.\n\n");
- printf("Costs of carts: \n\n");
- printf("6 - 6\n7 - 7\n8 - 8\n9 - 9\n10 - 10\nJ/D/K - 10\nA - 1/11(in ur choose)\n\n");
- printf("Press any key to start....");
- _getch();
- system("cls");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement