| 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 |
#define DOWN 0 |
| 27 |
|
| 28 |
static char *suits = "hdcs"; |
| 29 |
static char *values = "a234567890jqk"; |
| 30 |
|
| 31 |
static Picture *cards[52]; |
| 32 |
|
| 33 |
static Picture *empty, *back, *xemboss, *nodrop; |
| 34 |
|
| 35 |
static Stack *st[4]; |
| 36 |
|
| 37 |
#define W CARD_WIDTH |
| 38 |
#define H CARD_HEIGHT |
| 39 |
#define M CARD_MARGIN |
| 40 |
|
| 41 |
static void |
| 42 |
init() |
| 43 |
{ |
| 44 |
int s, v, t; |
| 45 |
char name[30]; |
| 46 |
|
| 47 |
for (s=0; s<4; s++) |
| 48 |
for (v=0; v<13; v++) |
| 49 |
{ |
| 50 |
sprintf(name, "%c%c", values[v], suits[s]); |
| 51 |
cards[v*4+s] = get_picture(name); |
| 52 |
} |
| 53 |
empty = get_picture("empty"); |
| 54 |
back = get_picture("back"); |
| 55 |
xemboss = get_picture("xemboss"); |
| 56 |
nodrop = get_picture("no-drop"); |
| 57 |
stack_set_pictures(cards, back); |
| 58 |
|
| 59 |
for (s=0; s<4; s++) |
| 60 |
{ |
| 61 |
#if DOWN |
| 62 |
st[s] = stack_create(CARD_MARGIN+s*(CARD_MARGIN+CARD_WIDTH), CARD_MARGIN); |
| 63 |
stack_set_offset(st[s], STACK_OFFSET_DOWN); |
| 64 |
#else |
| 65 |
st[s] = stack_create(CARD_MARGIN, CARD_MARGIN+s*(CARD_MARGIN+CARD_HEIGHT)); |
| 66 |
stack_set_offset(st[s], STACK_OFFSET_RIGHT); |
| 67 |
#endif |
| 68 |
for (v=0; v<13; v++) |
| 69 |
stack_add_card(st[s], MAKE_CARD(s, v, FACEUP)); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
static void |
| 74 |
redraw() |
| 75 |
{ |
| 76 |
int c; |
| 77 |
stack_redraw(); |
| 78 |
put_picture(xemboss, 500, M, 0, 0, xemboss->w, xemboss->h); |
| 79 |
put_picture(nodrop, 500, 100, 0, 0, nodrop->w, nodrop->h); |
| 80 |
} |
| 81 |
|
| 82 |
static void |
| 83 |
key(int k, int x, int y) |
| 84 |
{ |
| 85 |
if (k == 3 || k == 27 || k == 'q') |
| 86 |
exit(0); |
| 87 |
} |
| 88 |
|
| 89 |
static Stack *src_stack = 0; |
| 90 |
static int src_n = 0; |
| 91 |
|
| 92 |
static void |
| 93 |
click(int x, int y, int b) |
| 94 |
{ |
| 95 |
if (!stack_find(x, y, &src_stack, &src_n)) |
| 96 |
src_stack = 0; |
| 97 |
} |
| 98 |
|
| 99 |
static void |
| 100 |
drop(int x, int y, int b) |
| 101 |
{ |
| 102 |
Stack *dest_stack; |
| 103 |
int dest_n; |
| 104 |
if (src_stack && stack_find(x, y, &dest_stack, &dest_n)) |
| 105 |
stack_move_cards(src_stack, dest_stack, stack_count_cards(src_stack) - src_n, 0); |
| 106 |
} |
| 107 |
|
| 108 |
static FunctionMapping fmap[] = { |
| 109 |
{ "click", (void *)click }, |
| 110 |
{ "drop", (void *)drop }, |
| 111 |
{ "init", (void *)init }, |
| 112 |
{ "key", (void *)key }, |
| 113 |
{ "redraw", (void *)redraw }, |
| 114 |
{ 0, 0 } |
| 115 |
}; |
| 116 |
|
| 117 |
int |
| 118 |
main(int argc, char **argv) |
| 119 |
{ |
| 120 |
init_ace(argc, argv, fmap); |
| 121 |
#if DOWN |
| 122 |
init_table(4*W+5*M, 2*M+51*CARD_FAN_DOWN+H); |
| 123 |
#else |
| 124 |
init_table(2*M+51*CARD_FAN_RIGHT+W, 4*H+5*M); |
| 125 |
#endif |
| 126 |
table_loop(); |
| 127 |
} |