bj7
bj7
h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h> // For sleep()
#include "gfx.h"
#define NUM_CARDS 52
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
#define BUTTON_WIDTH 150
#define BUTTON_HEIGHT 50
// 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 checkDeckStatus();
void displayInstructions();
void displayHand(int x, int y, char handSuits[][10], char handFaces[][10], int
handValues[], int numCards, const char *owner);
void drawButton(int x, int y, const char *label, int r, int g, int b);
int isButtonClicked(int buttonX, int buttonY, int buttonWidth, int buttonHeight,
int mouseX, int mouseY);
void startNewGame();
void mainMenu();
int main() {
srand(time(0)); // Seed for random number generation
void mainMenu() {
while (1) {
gfx_clear_color(0, 128, 128);
gfx_clear();
// Title
gfx_color(255, 255, 255);
gfx_text((char*)"BLACKJACK 21", WINDOW_WIDTH / 2 - 100, 50, 2);
// Menu buttons
drawButton(WINDOW_WIDTH / 2 - 75, 150, "Start Game", 0, 200, 0);
drawButton(WINDOW_WIDTH / 2 - 75, 250, "Instructions", 0, 0, 200);
drawButton(WINDOW_WIDTH / 2 - 75, 350, "Exit", 200, 0, 0);
gfx_flush();
while (1) {
char event = gfx_wait();
int x = gfx_xpos(), y = gfx_ypos();
void startNewGame() {
gfx_clear_color(0, 128, 128);
gfx_clear();
// Draw buttons
drawButton(100, 500, "Hit", 0, 200, 0);
drawButton(300, 500, "Stand", 200, 0, 0);
gfx_flush();
}
void createDeck() {
const char *suitList[] = {"Diamonds", "Hearts", "Spades", "Clubs"};
const char *faceList[] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King"};
int faceValues[] = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
int index = 0;
for (int s = 0; s < 4; s++) {
for (int f = 0; f < 13; f++) {
strcpy(suits[index], suitList[s]);
strcpy(faces[index], faceList[f]);
values[index] = faceValues[f];
index++;
}
}
top = 0;
}
strcpy(handSuits[*numCards], suits[top]);
strcpy(handFaces[*numCards], faces[top]);
handValues[*numCards] = values[top];
top++;
(*numCards)++;
return 0;
}
void displayInstructions() {
gfx_clear();
gfx_color(255, 255, 255);
gfx_text((char*)"Instructions:", 50, 50, 2);
gfx_text((char*)"1. Goal: Get as close to 21 as possible without exceeding.",
50, 100, 1);
gfx_text((char*)"2. Hit: Draw another card. Stand: End your turn.", 50, 150,
1);
gfx_text((char*)"3. Dealer draws until 17 or higher.", 50, 200, 1);
gfx_flush();
sleep(5);
}