├── misc.c ├── stack_implementation.c ├── README.md ├── instructions.c ├── main.c ├── algorithm.txt ├── welcome_screen.c └── play.c /misc.c: -------------------------------------------------------------------------------- 1 | void stall() 2 | { 3 | for(int i = 0; i < 4500000; i++) 4 | ; 5 | } 6 | 7 | void stallLonger() 8 | { 9 | for(int i = 0; i < 5200000; i++) 10 | ; 11 | } 12 | 13 | void printstr(char string[]) 14 | { 15 | int i = 0; 16 | while (string[i] != '\0') 17 | { 18 | printf("%c", string[i]); 19 | stall(); 20 | stall(); 21 | i++; 22 | } 23 | } -------------------------------------------------------------------------------- /stack_implementation.c: -------------------------------------------------------------------------------- 1 | void push(int stack[], int n, int *top, int item) 2 | { 3 | if(*top == n - 1) 4 | printf("\nStack Overflow!\n"); 5 | else 6 | { 7 | ++*top; 8 | stack[*top] = item; 9 | } 10 | } 11 | 12 | int pop(int stack[], int n, int *top) 13 | { 14 | if(*top == -1) 15 | printf("\nStack Underflow!\n"); 16 | else 17 | { 18 | int item = stack[*top]; 19 | --*top; 20 | return item; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a source code of Popular Casino card game Blackjack in which the sum of your cards should be closer to 21 without getting over 21, if you go over 21, You lose! 2 | Players have a option to choose the value of their Ace cards as 11 or 1. The values of Jack, Queen and King is set to 10. If Yours and Computer’s cards sum is same, 3 | that will be a draw. 4 | 5 | The starting and ending of the program is handled by the main function while the core logic of the game is handled by the play function and its subfunctions. 6 | misc and welcome_screen are nothing but to add a fancy touch to the code at the runtime. 7 | Stack_implementation deals with the push and popping of the cards from the stack of cards, stack is used as this was a project in my college for data structure 8 | subject and had to use a data structure in the project. Alternative for this is just taking the cards from the deck array directly. 9 | -------------------------------------------------------------------------------- /instructions.c: -------------------------------------------------------------------------------- 1 | void instructions() 2 | { 3 | int emoji = 2; 4 | 5 | char w[] = "Welcome to Mr. Jackie's Blackjack!!"; 6 | printstr(w); 7 | printf("\n"); 8 | printf("\nThe rules are simple,\n ->the one with the sum of their cards closest to 21 without going over it wins!\n"); 9 | printf(" ->If player card's sum goes over 21, he/she losses irrespective of the hand of Mr. Jackie and so is the same for Mr. Jackie!\n"); 10 | printf(" ->Mr. Jackie will continue to draw cards until his cards add upto 17.\n"); 11 | printf(" ->hit = get another card, stand = hold your hand and reveal Mr. Jackie's cards.\n"); 12 | printf(" ->If a player gets an Ace, he/she will have an option to set the value of that card to 11 or 1, if\n"); 13 | printf(" the sum of your cards exceed with the value of ace as 11 then choose 1 and try your luck:)\n"); 14 | printf("Good Luck!%c\n", emoji); 15 | } -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "misc.c" 7 | #include "welcome_screen.c" 8 | #include "instructions.c" 9 | #include "play.c" 10 | #include "stack_implementation.c" 11 | 12 | int count = 0; 13 | 14 | void instructions(); 15 | void play(); 16 | void welcome(char[]); 17 | 18 | int main() 19 | { 20 | char n, emoji = 1; 21 | int flag; 22 | char x1[] = "Press any key to continue...."; 23 | 24 | if(count == 0) 25 | { 26 | welcome(x1); 27 | system("cls"); 28 | system("color f0"); 29 | instructions(); 30 | } 31 | 32 | printf("\n"); 33 | printstr(x1); 34 | getch(); 35 | 36 | play(); 37 | 38 | char x2[] = "->Do you want to play another hand?(Enter y to play again and n to exit): "; 39 | printf("\n"); 40 | printstr(x2); 41 | do 42 | { 43 | n = getchar(); 44 | }while(n != 'y' && n != 'n'); 45 | 46 | if(n == 'y') 47 | { 48 | char x3[] = "Ok, Good luck again!!"; 49 | printf("\n"); 50 | printstr(x3); 51 | printf("\n"); 52 | count++; 53 | main(); 54 | } 55 | else 56 | { 57 | char x4[] = "Thank you for playing Blackjack with Mr. Jackie!"; 58 | printf("\n"); 59 | printstr(x4); 60 | printf("%c\n", emoji); 61 | } 62 | 63 | return 0; 64 | } 65 | 66 | -------------------------------------------------------------------------------- /algorithm.txt: -------------------------------------------------------------------------------- 1 | main: 2 | 0.1: print the instructions using a function 3 | 0.2: clear screen and set console background color to "f0" 4 | 0.3: call play function 5 | 0.4: ask user if they want to play other hand, if no then exit 6 | ->if yes then repeat from 0.3 7 | 8 | play: 9 | 1.1: shuffle the cards using a function and push the shuffled cards to the stack of the cards 10 | 1.2: assign the top 2 cards of stack to user's cards(decrement top) and top 2 cards of stack to computer's cards(decrement top) 11 | 1.3: print one computer card and both of user's card 12 | 13 | 2.0-> 1st for loop: to convert face cards and ace card's value(for user) 14 | 2.1: if the card is ace, let user choose the value of ace as 11 or 1 and then add it to player cards sum 15 | 2.2: else if call convert_facecard function and if the rem is is 10 then add 10 to player cards sum 16 | 2.3: else add pcard[i]%100 to player cards sum 17 | 2.4: if(psum>21) then player loses 18 | 2.5: if(psum=21) then player wins 19 | 20 | 2.6-> print player card's sum 21 | 22 | 3.0-> 2nd for loop: whether player wants more cards 23 | 3.1: if user stands his hand(does not hit) then print his card's sum and exit the for loop. 24 | 3.2: [i=0]if user wants more cards then assign the card on top of stack(decrement top) to user and print that card. 25 | 3.3: repeat steps 2.1 to 2.5 26 | 3.4: goto step 3.1 27 | 28 | 3.5-> if player cards reach up to 5(i=3) and sum of player card's is less than 21 then player wins. 29 | 30 | 4.0-> print computer's two cards. 31 | 4.1: if both cards are aces then set comp cards sum to 12. 32 | 4.2: else if both cards add upto 21 its a blackjack and comp wins 33 | 4.3: else if any one card is ace then randomly select value of ace as 1 or 11. 34 | 4.4: else call convert_facecard functions for 1st[i] and 2nd card[1] and print comp card's sum 35 | 36 | 5.0-> 3rd for loop: giving cards to computer until sum of its cards is less than 17 37 | 5.1: for loop will only run through if comp cards sum is less than 17. 38 | 5.2: [i=0]assign top of stack card to comp card(i+2) and print that card. 39 | 5.3: if it is an ace then if the comp card sum is less than 21 then 11 is added to comp card sum else 1 is added. 40 | 5.4: else value returned from calling convert_facecard is added to comp card sum. 41 | 42 | 5.5-> if comp cards reach up to 5(i=3) and sum of comp card's is less than 21 then comp wins. 43 | 44 | 6.0-> if comp cards sum is greater than 21 or player sum is greater than comp card sum then player wins. 45 | 6.1: else if both sums are equal then it is a push. 46 | 6.2: else if player card sum is lesser than comp card sum than comp wins. -------------------------------------------------------------------------------- /welcome_screen.c: -------------------------------------------------------------------------------- 1 | #define SPACE " " 2 | 3 | void welcome(char x[]) 4 | { 5 | int i = 0, j = 0; 6 | char s = -33, t = 2; 7 | system("cls"); 8 | system("color 0f"); 9 | printf("\n\n\t\t\t\t\t\t\t\t\t WELCOME TO\n\n"); 10 | 11 | printf("\n\t\t\t%s%c%c%c%c%c%c%c%c %c%c%c\t %c%c%c%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c%c %c%c%c%c%c%c%c %c%c %c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 12 | printf("\n\t\t\t%s%c%c%c %c%c%c %c%c%c\t %c%c%c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c%c%c%c%c%c%c%c%c %c%c %c%c %c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 13 | printf("\n\t\t\t%s%c%c%c %c%c%c %c%c%c\t %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 14 | printf("\n\t\t\t%s%c%c%c %c%c%c %c%c%c\t %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 15 | printf("\n\t\t\t%s%c%c%c%c%c%c%c%c %c%c%c\t %c%c %c%c %c%c %c%c%c%c %c%c %c%c %c%c %c%c %c%c%c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 16 | printf("\n\t\t\t%s%c%c%c %c%c%c %c%c%c\t %c%c%c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c%c%c%c%c%c%c%c%c %c%c %c%c %c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 17 | printf("\n\t\t\t%s%c%c%c %c%c%c %c%c%c\t %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 18 | printf("\n\t\t\t%s%c%c%c %c%c%c %c%c%c%c%c%c%c%c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c %c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 19 | printf("\n\t\t\t%s%c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c %c%c %c%c %c%c%c%c%c %c%c %c%c %c%c%c%c%c%c%c %c%c %c%c", SPACE, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t, t); 20 | 21 | while(i < 6) 22 | { 23 | system("color 9"); 24 | stallLonger(); 25 | system("color 1"); 26 | stallLonger(); 27 | system("color 9"); 28 | stallLonger(); 29 | system("color A"); 30 | stallLonger(); 31 | system("color 2"); 32 | stallLonger(); 33 | system("color A"); 34 | stallLonger(); 35 | system("color B"); 36 | stallLonger(); 37 | system("color 3"); 38 | stallLonger(); 39 | system("color B"); 40 | stallLonger(); 41 | system("color C"); 42 | stallLonger(); 43 | system("color 4"); 44 | stallLonger(); 45 | system("color C"); 46 | stallLonger(); 47 | system("color D"); 48 | stallLonger(); 49 | system("color 5"); 50 | stallLonger(); 51 | system("color D"); 52 | stallLonger(); 53 | system("color E"); 54 | stallLonger(); 55 | system("color 6"); 56 | stallLonger(); 57 | system("color E"); 58 | stallLonger(); 59 | system("color F"); 60 | 61 | i++; 62 | } 63 | 64 | printf("\n\n\n\n\n\t\t\t\t\t\t\t\t"); 65 | printstr(x); 66 | getch(); 67 | printf("\n\n\n\n\n\t\t\t\t\t\t\t\tLOADING...\n\n\t\t\t\t\t\t\t\t"); 68 | 69 | for (j = 0; j < 3; j++) 70 | { 71 | printf("%c%c%c%c%c%c%c%c%c%c", s, s, s, s, s, s, s, s, s, s); 72 | sleep(1); 73 | } 74 | } -------------------------------------------------------------------------------- /play.c: -------------------------------------------------------------------------------- 1 | #define CardPattern_1 "*************\n" 2 | #define CardPattern_2 "* *\n" 3 | 4 | // 3 = hearts 5 | // 4 = diamonds 6 | // 5 = clubs 7 | // 6 = spades 8 | 9 | int convert_facecards(int); 10 | void shuffle_cards(int []); 11 | void print_card(int); 12 | void push(int [], int, int *, int); 13 | int pop(int [], int, int *); 14 | void stall(); 15 | void stallLonger(); 16 | void printstr(char []); 17 | 18 | void play() 19 | { 20 | int i, psum = 0, compsum = 0, emoji = 1, totalcards = 52, top = -1; 21 | int deck[52]; 22 | int stackofcards[52]; 23 | int pcards[5] = {0}; 24 | int compcards[5] = {0}; 25 | char n; 26 | 27 | shuffle_cards(deck); 28 | 29 | for(i = 0; i < 52; i++) 30 | push(stackofcards, totalcards, &top, deck[i]); 31 | 32 | pcards[0] = pop(stackofcards, totalcards, &top); 33 | pcards[1] = pop(stackofcards, totalcards, &top); 34 | compcards[0] = pop(stackofcards, totalcards, &top); 35 | compcards[1] = pop(stackofcards, totalcards, &top); 36 | 37 | char y1[] = " >-> You've chosen the value of Ace as 11."; 38 | char y2[] = " >-> You've chosen the value of Ace as 1."; 39 | char y3[] = "~Mr. Jackie's cards:"; 40 | char w1[] = "~Mr. Jackie's 1st card:"; 41 | char w2[] = "~Your cards:"; 42 | 43 | printf("\n\n"); 44 | printstr(w1); 45 | printf("\n"); 46 | print_card(compcards[0]); 47 | printstr(w2); 48 | printf("\n"); 49 | print_card(pcards[0]); 50 | print_card(pcards[1]); 51 | 52 | for(i = 0; i < 2; i++) 53 | { 54 | if(pcards[i] % 100 == 1) 55 | { 56 | printf("->Choose the value of Ace for card %d, (Enter a for 11 and b for 1): ", i + 1); 57 | do 58 | { 59 | n = getchar(); 60 | }while((n != 'a') && (n != 'b')); 61 | 62 | if(n == 'a') 63 | { 64 | printf("\n"); 65 | printstr(y1); 66 | printf("\n"); 67 | psum += 11; 68 | } 69 | else 70 | { 71 | printf("\n"); 72 | printstr(y2); 73 | printf("\n"); 74 | psum += 1; 75 | } 76 | } 77 | else if(convert_facecards(pcards[i]) % 100 == 10) 78 | psum += 10; 79 | else 80 | psum += pcards[i] % 100; 81 | 82 | if(psum > 21) 83 | { 84 | printstr(y3); 85 | printf("\n"); 86 | print_card(compcards[0]); 87 | print_card(compcards[1]); 88 | char y4[] = " >-> Mr. Jackie WINS!! because the sum of your cards is over 21!"; 89 | printf("\n"); 90 | printstr(y4); 91 | printf("\n"); 92 | return; 93 | } 94 | } 95 | 96 | char y5[] = " >-> SUM OF YOUR CARDS CURRENTLY is "; 97 | printstr(y5); 98 | printf("%d\n", psum); 99 | stallLonger(); 100 | stallLonger(); 101 | 102 | if(psum == 21) 103 | { 104 | if((((convert_facecards(compcards[0])) % 100 == 1) && ((convert_facecards(compcards[1])) % 100 == 10)) || (((convert_facecards(compcards[0])) % 100 == 10) && ((convert_facecards(compcards[1])) % 100 == 1))) 105 | { 106 | printf("\n~Mr. Jackie's cards:\n"); 107 | print_card(compcards[0]); 108 | print_card(compcards[1]); 109 | char y6[] = " >-> Push! its a draw, you and Mr. Jackie both have a Blackjack"; 110 | printf("\n"); 111 | printstr(y6); 112 | printf("\n"); 113 | return; 114 | } 115 | else 116 | { 117 | printf("\n~Mr. Jackie's cards:\n"); 118 | print_card(compcards[0]); 119 | print_card(compcards[1]); 120 | char y7[] = " >-> You WIN!! Its a blackjack!"; 121 | printstr(y7); 122 | printf("\n"); 123 | return; 124 | } 125 | } 126 | 127 | for(i = 0; i < 3; i++) 128 | { 129 | char y8[] = "->Do you want to HIT or STAND?(Enter h to hit and s to stand): "; 130 | printf("\n"); 131 | printstr(y8); 132 | do 133 | { 134 | n = getchar(); 135 | }while((n != 'h') && (n != 's')); 136 | 137 | if(n == 'h') 138 | { 139 | pcards[i + 2] = pop(stackofcards, totalcards, &top); 140 | printf("\nYour card %d is:\n", i + 3); 141 | print_card(pcards[i + 2]); 142 | 143 | if(pcards[i + 2] % 100 == 1) 144 | { 145 | printf("->Choose the value of Ace for card %d, (Enter a for 11 and b for 1): ", i + 1); 146 | do 147 | { 148 | n = getchar(); 149 | }while((n != 'a') && (n != 'b')); 150 | 151 | if(n == 'a') 152 | { 153 | printstr(y1); 154 | printf("\n"); 155 | psum += 11; 156 | } 157 | else 158 | { 159 | printstr(y2); 160 | printf("\n"); 161 | psum += 1; 162 | } 163 | } 164 | else if(convert_facecards(pcards[i + 2]) % 100 == 10) 165 | psum += 10; 166 | else 167 | psum += pcards[i + 2] % 100; 168 | 169 | printstr(y5); 170 | printf("%d\n", psum); 171 | stallLonger(); 172 | stallLonger(); 173 | 174 | if(psum > 21) 175 | { 176 | printf("\n"); 177 | printstr(y3); 178 | printf("\n"); 179 | print_card(compcards[0]); 180 | print_card(compcards[1]); 181 | char y9[] = " >-> Mr. Jackie WINS!! because the sum of your cards is over 21!"; 182 | printstr(y9); 183 | printf("\n"); 184 | return; 185 | } 186 | 187 | if(psum == 21) 188 | break; 189 | } 190 | else 191 | { 192 | char y10[] = " >-> FINAL SUM OF YOUR CARDS is "; 193 | printf("\n"); 194 | printstr(y10); 195 | printf("%d\n", psum); 196 | stallLonger(); 197 | stallLonger(); 198 | break; 199 | } 200 | } 201 | 202 | if((i == 3) && (psum <= 21)) 203 | { 204 | char y11[] = " >-> You WIN!! because the sum of your 5 cards is no larger than 21! you're quite lucky!!"; 205 | printstr(y11); 206 | printf("\n"); 207 | return; 208 | } 209 | 210 | char m1[] = "~Mr. Jackie's first 2 cards:"; 211 | char m2[] = " >-> Sum of Mr. Jackie's cards currently is "; 212 | 213 | char n1[] = " >-> Mr. Jackie chosen the value of Ace as 11."; 214 | char n2[] = " >-> Mr. Jackie chosen the value of Ace as 1."; 215 | 216 | printf("\n"); 217 | printstr(m1); 218 | printf("\n"); 219 | print_card(compcards[0]); 220 | print_card(compcards[1]); 221 | 222 | if(compcards[0] % 100 + compcards[1] % 100 == 2) 223 | { 224 | compsum = 12; 225 | printstr(m2); 226 | printf("%d\n", compsum); 227 | stallLonger(); 228 | stallLonger(); 229 | } 230 | else if((((convert_facecards(compcards[0])) % 100 == 1) && ((convert_facecards(compcards[1])) % 100 == 10)) || (((convert_facecards(compcards[0])) % 100 == 10) && ((convert_facecards(compcards[1])) % 100 == 1))) 231 | { 232 | compsum = 21; 233 | printstr(m2); 234 | printf("%d\n", compsum); 235 | 236 | char m3[] = " >-> Mr. Jackie WINS as he has a BLACKJACK! better luck next time!"; 237 | printf("\n"); 238 | printstr(m3); 239 | printf("\n"); 240 | return; 241 | } 242 | else if((compcards[0] % 100 == 1) || (compcards[1] % 100 == 1)) 243 | { 244 | compsum = ((compcards[0] % 100) + (compcards[1]) % 100) + (rand() % 2) * 10; 245 | printstr(m2); 246 | printf("%d\n", compsum); 247 | } 248 | else 249 | { 250 | compsum = (convert_facecards(compcards[0]) % 100 + convert_facecards(compcards[1]) % 100); 251 | printstr(m2); 252 | printf("%d\n", compsum); 253 | } 254 | 255 | for(i = 0; i < 3 && compsum < 17; i++) 256 | { 257 | compcards[i + 2] = pop(stackofcards, totalcards, &top); 258 | printf("\n >-> Mr. Jackie's card %d is:\n", i + 3); 259 | print_card(compcards[i + 2]); 260 | 261 | if(compcards[i + 2] % 100 == 1) 262 | { 263 | if(compsum < 21) 264 | { 265 | compsum += 11; 266 | printstr(n1); 267 | printf("\n"); 268 | printstr(m2); 269 | printf("%d\n", compsum); 270 | } 271 | else 272 | { 273 | compsum += 1; 274 | printstr(n2); 275 | printf("\n"); 276 | printstr(m2); 277 | printf("%d\n", compsum); 278 | } 279 | } 280 | else 281 | { 282 | compsum += (convert_facecards(compcards[i + 2])) % 100; 283 | printstr(m2); 284 | printf("%d\n", compsum); 285 | } 286 | } 287 | 288 | if((i == 3) && (compsum <= 21)) 289 | { 290 | char o1[] = " >-> Mr. Jackie WINS because the sum of his 5 cards is no larger than 21! He is quite lucky!!"; 291 | printf("\n"); 292 | printstr(o1); 293 | printf("\n"); 294 | return; 295 | } 296 | 297 | if((compsum > 21) || (psum > compsum)) 298 | { 299 | char o2[] = " >-> You WIN!!"; 300 | printf("\n"); 301 | printstr(o2); 302 | printf("%c\n", emoji); 303 | return; 304 | } 305 | else if(psum == compsum) 306 | { 307 | char o3[] = " >-> Push! its a draw, yours and Mr. Jackie's card add up to the same!"; 308 | printf("\n"); 309 | printstr(o3); 310 | printf("\n"); 311 | return; 312 | } 313 | else if(compsum > psum) 314 | { 315 | char o4[] = " >-> Mr. Jackie WINS!! better luck next time!"; 316 | printf("\n"); 317 | printstr(o4); 318 | printf("\n"); 319 | return; 320 | } 321 | } 322 | 323 | int convert_facecards(int val) 324 | { 325 | if((val % 100 == 11) || (val % 100 == 12) || (val % 100 == 13)) 326 | return ((val / 100) * 100 + 10); 327 | else 328 | return val; 329 | } 330 | 331 | void shuffle_cards(int deck[]) 332 | { 333 | int i, temp; 334 | int tempdeck[52]; 335 | 336 | for(i = 0; i < 52; i++) 337 | tempdeck[i] = (((i / 13 + 3) * 100) + (i % 13) + 1); 338 | 339 | srand(time(NULL)); 340 | for(i = 0; i < 52; i++) 341 | { 342 | do 343 | { 344 | temp = rand() % 52; 345 | }while(tempdeck[temp] == 0); 346 | 347 | deck[i] = tempdeck[temp]; 348 | tempdeck[temp] = 0; 349 | } 350 | } 351 | 352 | void print_card(int card) 353 | { 354 | char suit; 355 | int value; 356 | 357 | suit = card / 100; 358 | value = card % 100; 359 | 360 | switch(value) 361 | { 362 | case 1: 363 | { 364 | printf("%s", CardPattern_1); 365 | printf("* A *\n"); 366 | printf("%s", CardPattern_2); 367 | printf("%s", CardPattern_2); 368 | printf("* %c *\n", suit); 369 | printf("%s", CardPattern_2); 370 | printf("%s", CardPattern_2); 371 | printf("* A *\n"); 372 | printf("%s", CardPattern_1); 373 | 374 | break; 375 | } 376 | 377 | case 2: 378 | case 3: 379 | case 4: 380 | case 5: 381 | case 6: 382 | case 7: 383 | case 8: 384 | case 9: 385 | case 10: 386 | { 387 | printf("%s", CardPattern_1); 388 | printf("*%2d *\n", value); 389 | printf("%s", CardPattern_2); 390 | printf("%s", CardPattern_2); 391 | printf("* %c *\n", suit); 392 | printf("%s", CardPattern_2); 393 | printf("%s", CardPattern_2); 394 | printf("* %2d*\n", value); 395 | printf("%s", CardPattern_1); 396 | 397 | break; 398 | } 399 | 400 | case 11: 401 | { 402 | printf("%s", CardPattern_1); 403 | printf("* J *\n"); 404 | printf("%s", CardPattern_2); 405 | printf("%s", CardPattern_2); 406 | printf("* %c *\n", suit); 407 | printf("%s", CardPattern_2); 408 | printf("%s", CardPattern_2); 409 | printf("* J *\n"); 410 | printf("%s", CardPattern_1); 411 | 412 | break; 413 | } 414 | 415 | case 12: 416 | { 417 | printf("%s", CardPattern_1); 418 | printf("* Q *\n"); 419 | printf("%s", CardPattern_2); 420 | printf("%s", CardPattern_2); 421 | printf("* %c *\n", suit); 422 | printf("%s", CardPattern_2); 423 | printf("%s", CardPattern_2); 424 | printf("* Q *\n"); 425 | printf("%s", CardPattern_1); 426 | 427 | break; 428 | } 429 | 430 | case 13: 431 | { 432 | printf("%s", CardPattern_1); 433 | printf("* K *\n"); 434 | printf("%s", CardPattern_2); 435 | printf("%s", CardPattern_2); 436 | printf("* %c *\n", suit); 437 | printf("%s", CardPattern_2); 438 | printf("%s", CardPattern_2); 439 | printf("* K *\n"); 440 | printf("%s", CardPattern_1); 441 | break; 442 | } 443 | } 444 | printf("\n"); 445 | } --------------------------------------------------------------------------------