BJ 15
BJ 15
h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
// Button dimensions
#define BUTTON_WIDTH 100
#define BUTTON_HEIGHT 40
// Function prototypes
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 draw_card(int x, int y, const char *suit, const char *face);
void draw_button(int x, int y, const char *label);
int is_button_clicked(int bx, int by, int bw, int bh, int mx, int my);
void display_hand_graphics(int x_start, int y, char handSuits[][10], char
handFaces[][10], int numCards, const char *owner);
int calculateHandValue(char handSuits[][10], char handFaces[][10], int
handValues[], int numCards);
void game_loop();
return 0;
}
// Game loop
void game_loop() {
// Card arrays and variables
char suits[52][10] = {"Hearts", "Diamonds", "Clubs", "Spades"};
char faces[13][10] = {"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10",
"Jack", "Queen", "King"};
int faceValues[13] = {11, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10};
char playerSuits[10][10], dealerSuits[10][10];
char playerFaces[10][10], dealerFaces[10][10];
int playerValues[10], dealerValues[10];
int playerCards = 0, dealerCards = 0;
// Initial deal
strcpy(playerSuits[0], suits[0]);
strcpy(playerFaces[0], faces[0]);
playerValues[0] = faceValues[0];
playerCards++;
strcpy(dealerSuits[0], suits[1]);
strcpy(dealerFaces[0], faces[1]);
dealerValues[0] = faceValues[1];
dealerCards++;
while (1) {
gfx_clear(); // Clear screen
// Draw buttons
draw_button(hit_x, hit_y, "Hit");
draw_button(stand_x, stand_y, "Stand");
// Flush graphics
gfx_flush();
// Final results
int playerTotal = calculateHandValue(playerSuits, playerFaces,
playerValues, playerCards);
int dealerTotal = calculateHandValue(dealerSuits, dealerFaces,
dealerValues, dealerCards);
gfx_flush();
sleep(3);
break;
} else if (c == 'q') {
break; // Quit the game
}
}
}
// Draw a button
void draw_button(int x, int y, const char *label) {
gfx_color(200, 200, 200); // Button background
gfx_fillrectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
gfx_color(0, 0, 0); // Button border and text
gfx_rectangle(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
gfx_text((char *)label, x + 10, y + 25, small);
}
return total;
}