| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include <stdlib.h> |
| 19 |
#include <stdio.h> |
| 20 |
#include <string.h> |
| 21 |
#include <time.h> |
| 22 |
|
| 23 |
#include "table.h" |
| 24 |
#include "cards.h" |
| 25 |
|
| 26 |
static char *suits = "hdcs"; |
| 27 |
static char *values = "a234567890jqk"; |
| 28 |
|
| 29 |
static Picture *cards[52]; |
| 30 |
static Picture *back; |
| 31 |
static int cx[52]; |
| 32 |
static int cy[52]; |
| 33 |
|
| 34 |
static Picture *empty; |
| 35 |
|
| 36 |
#define W CARD_WIDTH |
| 37 |
#define H CARD_HEIGHT |
| 38 |
#define M CARD_MARGIN |
| 39 |
|
| 40 |
static Stack *st; |
| 41 |
|
| 42 |
static void |
| 43 |
init() |
| 44 |
{ |
| 45 |
int s, v, t; |
| 46 |
char name[30]; |
| 47 |
|
| 48 |
for (s=0; s<4; s++) |
| 49 |
for (v=0; v<13; v++) |
| 50 |
{ |
| 51 |
sprintf(name, "%c%c", values[v], suits[s]); |
| 52 |
cards[v*4+s] = get_picture(name); |
| 53 |
cx[v*4+s] = M+v*(M+W); |
| 54 |
cy[v*4+s] = M+s*(M+H); |
| 55 |
} |
| 56 |
empty = get_picture("empty"); |
| 57 |
back = get_picture("back"); |
| 58 |
|
| 59 |
stack_set_pictures(cards, back); |
| 60 |
|
| 61 |
st = stack_create(CARD_MARGIN, CARD_MARGIN); |
| 62 |
stack_set_offset(st, STACK_OFFSET_RIGHT); |
| 63 |
stack_shuffle(st); |
| 64 |
for (s=0; s<52; s++) |
| 65 |
{ |
| 66 |
if (rand() & 64) |
| 67 |
stack_add_card(st, s); |
| 68 |
else |
| 69 |
stack_add_card(st, s | 64); |
| 70 |
} |
| 71 |
stack_shuffle(st); |
| 72 |
} |
| 73 |
|
| 74 |
static void |
| 75 |
redraw() |
| 76 |
{ |
| 77 |
stack_redraw(); |
| 78 |
} |
| 79 |
|
| 80 |
static FunctionMapping fmap[] = { |
| 81 |
{ "init", (void *)init }, |
| 82 |
{ "redraw", (void *)redraw }, |
| 83 |
{ 0, 0 } |
| 84 |
}; |
| 85 |
|
| 86 |
int |
| 87 |
main(int argc, char **argv) |
| 88 |
{ |
| 89 |
init_ace(argc, argv, fmap); |
| 90 |
init_table(W+2*M+51*CARD_FAN_RIGHT, 2*M+H); |
| 91 |
table_loop(); |
| 92 |
} |