BJ 14
BJ 14
h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "gfx.h" // Include the gfx library
// Function Prototypes
void createDeck();
void shuffleDeck();
int dealCard(char handSuits[][10], char handFaces[][10], int handValues[], int
*numCards);
int calculateHandValue(char handSuits[][10], char handFaces[][10], int
handValues[], int numCards);
void displayHand(char handSuits[][10], char handFaces[][10], int handValues[], int
numCards, const char *owner);
void drawCard(int x, int y, const char *face, const char *suit, float size);
void draw_heart(int x, int y, float size);
void draw_diamond(int x, int y, float size);
void draw_club(int x, int y, float size);
void draw_spade(int x, int y, float size);
void displayHelp();
// Main function
int main() {
srand(time(0)); // Seed for random number generation
while (1) {
gfx_clear();
gfx_color(255, 255, 255);
gfx_text(50, 50, "Welcome to the Blackjack Game!");
gfx_text(50, 100, "1. Start Game");
gfx_text(50, 140, "2. Help");
gfx_text(50, 180, "3. Exit");
if (input == '1') {
gfx_clear();
// Example hand display for demonstration
char handSuits[3][10] = {"Hearts", "Clubs", "Spades"};
char handFaces[3][10] = {"A", "10", "K"};
int handValues[3] = {11, 10, 10};
displayHand(handSuits, handFaces, handValues, 3, "Player");
gfx_text(50, WINDOW_HEIGHT - 50, "Press any key to return to the main
menu.");
gfx_wait();
} else if (input == '2') {
gfx_clear();
displayHelp();
gfx_text(50, WINDOW_HEIGHT - 50, "Press any key to return to the main
menu.");
gfx_wait();
} else if (input == '3') {
gfx_close();
printf("Thank you for playing! Goodbye!\n");
exit(0);
} else {
gfx_text(50, 300, "Invalid input. Please select a valid option (1-
3).");
}
}
return 0;
}
int index = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 13; j++) {
strcpy(suits[index], suitsList[i]);
strcpy(faces[index], facesList[j]);
values[index] = faceValues[j];
index++;
}
}
}
// Swap suits
strcpy(tempSuit, suits[i]);
strcpy(suits[i], suits[j]);
strcpy(suits[j], tempSuit);
// Swap faces
strcpy(tempFace, faces[i]);
strcpy(faces[i], faces[j]);
strcpy(faces[j], tempFace);
// Swap values
tempValue = values[i];
values[i] = values[j];
values[j] = tempValue;
}
}
return total;
}