Initial checkin of a portable framework for writing small GUI puzzle
[sgt/puzzles] / puzzles.h
CommitLineData
720a8fb7 1/*
2 * puzzles.h: header file for my puzzle collection
3 */
4
5#ifndef PUZZLES_PUZZLES_H
6#define PUZZLES_PUZZLES_H
7
8#ifndef TRUE
9#define TRUE 1
10#endif
11#ifndef FALSE
12#define FALSE 0
13#endif
14
15#define lenof(array) ( sizeof(array) / sizeof(*(array)) )
16
17enum {
18 LEFT_BUTTON = 0x1000,
19 MIDDLE_BUTTON,
20 RIGHT_BUTTON
21};
22
23/*
24 * Platform routines
25 */
26void fatal(char *fmt, ...);
27
28/*
29 * malloc.c
30 */
31void *smalloc(int size);
32void *srealloc(void *p, int size);
33void sfree(void *p);
34char *dupstr(char *s);
35#define snew(type) \
36 ( (type *) smalloc (sizeof (type)) )
37#define snewn(number, type) \
38 ( (type *) smalloc ((number) * sizeof (type)) )
39#define sresize(array, number, type) \
40 ( (type *) srealloc ((array), (len) * sizeof (type)) )
41
42/*
43 * random.c
44 */
45typedef struct random_state random_state;
46random_state *random_init(char *seed, int len);
47unsigned long random_upto(random_state *state, unsigned long limit);
48void random_free(random_state *state);
49
50/*
51 * Game-specific routines
52 */
53typedef struct game_params game_params;
54typedef struct game_state game_state;
55char *new_game_seed(game_params *params);
56game_state *new_game(game_params *params, char *seed);
57game_state *dup_game(game_state *state);
58void free_game(game_state *state);
59game_state *make_move(game_state *from, int x, int y, int button);
60
61#endif /* PUZZLES_PUZZLES_H */