X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=kub.c;h=a83555d3977a93713e3464c89b7ccd70a84998df;hb=cbbf53a2e5e9391f87375ce8a3c2fb18fef3f7c8;hp=326856bfc326d954394e55a27169b93728ef17c8;hpb=da6cb72d21c540631238e0f3a974dc814aea8a9c;p=kub diff --git a/kub.c b/kub.c index 326856b..a83555d 100644 --- a/kub.c +++ b/kub.c @@ -2,6 +2,11 @@ #include #include #include +#include +#include + +#define FATAL_ERROR(msg) \ + do { fprintf (stderr, "Error: %s\n", msg); exit (1); } while (0) char *colors[] = {"Black", "Blue", "Red", "Yellow"}; @@ -46,6 +51,7 @@ typedef struct game { int num_players; board_t board; deck_t deck; + RsvgHandle *blanktile; } game_t; static void card_print(card_t card) @@ -285,9 +291,36 @@ static void hand_print(game_t *game) } } +static void card_draw(game_t *game, card_t *card, cairo_t *cr, int x, int y) +{ + char number_string[2]; + number_string[0] = &card->number; + number_string[1] = '\0'; + + cairo_save(cr); + cairo_translate(cr, x, y); + rsvg_handle_render_cairo (game->blanktile, cr); + + if (&card->color == BLACK) + cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); + if (&card->color == BLUE) + cairo_set_source_rgb (cr, 0.0, 0.0, 1.0); + if (&card->color == RED) + cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); + if (&card->color == YELLOW) + cairo_set_source_rgb (cr, 1.0, 1.0, 0.0); + cairo_move_to (cr, 0, 25); + cairo_set_font_size(cr, 25); + cairo_show_text (cr, number_string[0]); + + cairo_restore(cr); +} + static void game_init(game_t *game) { int i; + GError *error = NULL; + game->num_players = 0; for (i = 0; i < GAME_MAX_PLAYERS; ++i) @@ -299,6 +332,10 @@ static void game_init(game_t *game) board_init(&game->board); deck_init(&game->deck); deck_shuffle(&game->deck); + + game->blanktile = rsvg_handle_new_from_file ("tiles/blanktile.svg", &error); + if (error) + FATAL_ERROR (error->message); } static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, game_t *game) @@ -307,9 +344,8 @@ static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, game_ cr = gdk_cairo_create (widget->window); - cairo_set_source_rgb (cr, 1, 0, 0); /* red */ - cairo_rectangle (cr, 86, 66, 74, 103); - cairo_fill (cr); + rsvg_handle_render_cairo (game->blanktile, cr); + card_draw(game, game->deck.cards[0], cr, 320, 240); cairo_destroy (cr); @@ -343,15 +379,15 @@ int main(int argc, char *argv[]) game_t game; srand(time(NULL)); + + gtk_init (&argc, &argv); game_init(&game); deck_print(&game.deck); - deck_deal(&game, &game.deck); + //deck_deal(&game, &game.deck); hand_print(&game); deck_print(&game.deck); - gtk_init (&argc, &argv); - /* Create a new window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_default_size (GTK_WINDOW (window),