1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  */
12 
13 
14 #define BOARD_W 6
15 #define BOARD_H 16
16 
17 enum game_state {
18 	GAME_STATE_IDLE,
19 	GAME_STATE_START,
20 	GAME_STATE_PLAY,
21 	GAME_STATE_PAUSE,
22 	GAME_STATE_GAME_OVER,
23 };
24 
25 
26 enum game_action_id {
27 	GAME_ACTION_START,
28 	GAME_ACTION_TICK,
29 	GAME_ACTION_UP,
30 	GAME_ACTION_DOWN,
31 	GAME_ACTION_LEFT,
32 	GAME_ACTION_RIGHT,
33 	GAME_ACTION_FLIP,
34 	GAME_ACTION_PAUSE,
35 	GAME_ACTION_EARTHQUAKE,
36 	GAME_ACTION_SET_CURSOR,
37 };
38 
39 struct game_action_set_cursor {
40 	int x;
41 	int y;
42 };
43 
44 struct game_action {
45 	enum game_action_id id;
46 	union {
47 		struct game_action_set_cursor set_cursor;
48 	} data;
49 };
50 
51 
52 enum game_event_id {
53 	GAME_EVENT_START,
54 	GAME_EVENT_EXPLODING,
55 	GAME_EVENT_SCORE_UPDATE,
56 	GAME_EVENT_NEW_BLOCK,
57 	GAME_EVENT_FALL,
58 	GAME_EVENT_GAME_OVER,
59 	GAME_EVENT_HURRY,
60 	GAME_EVENT_EARTHQUAKE,
61 };
62 
63 struct game_event_exploding {
64 	int points;
65 	int blocks;
66 	int x;
67 	int y;
68 };
69 
70 struct game_event {
71 	enum game_event_id id;
72 	union {
73 		struct game_event_exploding exploding;
74 	} data;
75 };
76 
77 struct cell_t {
78 	int contents;
79 	int falling;
80 	int prev_falling;
81 	int fallen;
82 	int exploding;
83 	int same;
84 };
85 
86 struct game_t {
87 
88 	enum game_state state;
89 	struct cell_t cell[BOARD_W][BOARD_H];
90 
91 	int num_blocks;
92 
93 	int cursor_x;
94 	int cursor_y;
95 
96 	int score;
97 	int score_counter;
98 
99 	int time;
100 	int earthquake_available;
101 	int earthquake_counter;
102 
103 	void (*callback)(struct game_t *g, struct game_event *event);
104 };
105 
106 
107 struct game_t *game_new(void);
108 int game_do(struct game_t *g, struct game_action *action);
109 void game_register_callback(struct game_t *g, void (*callback)(struct game_t *g, struct game_event *event));
110 
111 /*
112  * End
113  */
114 
115