X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=kub.c;h=326856bfc326d954394e55a27169b93728ef17c8;hb=da6cb72d21c540631238e0f3a974dc814aea8a9c;hp=92cc533fdc74f6ae46c4e9879b9cb2a7928f3a09;hpb=8a3a5d075300ac2fa9827f7c5a94906b10598863;p=kub diff --git a/kub.c b/kub.c index 92cc533..326856b 100644 --- a/kub.c +++ b/kub.c @@ -75,12 +75,38 @@ static void player_init(player_t *player) } +/* If card_one < card_two, then return value will be negative + if they are equal, 0 will be returned, + if card_one > card_two, then return value will be positive */ static int card_compare(card_t *card_one, card_t *card_two) { return card_one->number - card_two->number; } -static int card_group_is_run(card_group_t *card_group) +static int card_group_is_run_one(card_group_t *card_group) +{ + int i; + qsort (&card_group->cards[0], card_group->num_cards, + sizeof (card_t), card_compare); + + if (card_group->num_cards > 13 || card_group->num_cards < 3) + { + return 0; + } + for (i = 0; i < card_group->num_cards - 1; ++i) + if(card_group->cards[i].color != card_group->cards[i + 1].color) + { + return 0; + } + if(card_group->cards[i].number != card_group->cards[i + 1].number -1) + { + return 0; + } + return 1; +} + + +static int card_group_is_run_two(card_group_t *card_group) { int i; int lowest = 14, highest = 0; @@ -99,7 +125,8 @@ static int card_group_is_run(card_group_t *card_group) /* Loop through all cards in the group, ensuring that they are all * the same color and finding the highest and lowest number in the * group. */ - run_color = card_group->cards[i].color; + run_color = card_group->cards[0].color; + for (i = 0; i < card_group->num_cards; i++) { if (card_group->cards[i].color != run_color) @@ -276,7 +303,15 @@ static void game_init(game_t *game) static gboolean on_expose_event (GtkWidget *widget, GdkEventExpose *event, game_t *game) { - printf ("I should be drawing something here\n"); + cairo_t *cr; + + 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); + + cairo_destroy (cr); return TRUE; }