X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=kub.c;h=912daded8e862b97c1bbb94a34e6755871a720a3;hb=9a6cebd91e1c580cffcdd850277240c22a0f7287;hp=bad09fdb9ccaf3ba73150be4a6539efcb396b443;hpb=38a73833906ed36e3c961545bfd51f7c215596b1;p=kub diff --git a/kub.c b/kub.c index bad09fd..912dade 100644 --- a/kub.c +++ b/kub.c @@ -15,6 +15,8 @@ typedef enum {BLACK, BLUE, RED, YELLOW} color_t; typedef struct tile { color_t color; int number; + int x; + int y; } tile_t; #define DECK_MAX_TILES 104 @@ -54,12 +56,21 @@ typedef struct game { RsvgHandle *blanktile; } game_t; +static void +tile_init (tile_t *tile, color_t color, int number) +{ + tile->color = color; + tile->number = number; + tile->x = 0; + tile->y = 0; +} + static void tile_print(tile_t tile) { printf("%6s %2d\n", colors[tile.color], tile.number + 1); } -static void tile_draw(game_t *game, tile_t *tile, cairo_t *cr, int x, int y) +static void tile_draw(game_t *game, tile_t *tile, cairo_t *cr) { char number_string[3]; int len; @@ -69,7 +80,7 @@ static void tile_draw(game_t *game, tile_t *tile, cairo_t *cr, int x, int y) FATAL_ERROR ("snprintf failed"); cairo_save(cr); - cairo_translate(cr, x, y); + cairo_translate(cr, tile->x, tile->y); rsvg_handle_render_cairo (game->blanktile, cr); if (tile->color == BLACK) @@ -273,9 +284,7 @@ static void deck_init(deck_t *deck) { for (j = 0; j <= 12; ++j) { - deck->tiles[j + (i * 13) + (h * 52)].color = i; - deck->tiles[j + (i * 13) + (h * 52)].number = j; - deck->num_tiles += 1; + tile_init (&deck->tiles[deck->num_tiles++], i, j); printf ("There are %d tiles in the deck\n", deck->num_tiles); } } @@ -320,8 +329,7 @@ static void deck_draw(game_t *game, cairo_t *cr) { for (j = 0; j < 13; ++j) { - tile_draw(game, &game->deck.tiles[j + (i * 13)], - cr, 45 * j, 55 * i); + tile_draw(game, &game->deck.tiles[j + (i * 13)], cr); } } }