Debian Codegraph @

tests/test4.c

raw symbols SCIP
1 /* The Ace of Penguins - test4.c
2 Copyright (C) 1998, 2001 DJ Delorie
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
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 }