Debian Codegraph @

tests/test3.c

raw symbols SCIP
1 /* The Ace of Penguins - test3.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 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 }