-
Notifications
You must be signed in to change notification settings - Fork 0
/
tetris.h
58 lines (44 loc) · 1.32 KB
/
tetris.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef _tetris_h
#define _tetris_h
#define BOARDW 10
#define BOARDH 22
enum tetromino_id {
TETRO_I, TETRO_J, TETRO_L, TETRO_O, TETRO_S, TETRO_T, TETRO_Z, TETRO_NONE
};
enum play_mode {
MODE_PLAY, MODE_REPLAY
};
struct tetromino {
int id;
int x, y, r;
};
struct tetromino_queue {
int ids[14];
int idx;
};
struct tetris {
int **board;
struct tetromino falling;
struct tetromino_queue queue;
int holdid, canhold;
};
struct statistics {
int linescleared;
int mselapsed;
int tetrosplaced;
};
int TETRO_COORDS[7][4][4][2]; /* 4 (x, y) coords for 4 rotations for 7 tetros */
void place_tetro(struct tetromino *tetro, int x, int y, int r);
void move_tetro(struct tetromino *tetro, int dx, int dy, int dr);
int legal_move(int **board, struct tetromino *tetro, int dx, int dy, int dr);
int try_translate_tetro(int **board, struct tetromino *tetro, int dx, int dy);
int try_rotate_tetro(int **board, struct tetromino *tetro, int dr);
void spawn_tetro(int id, struct tetromino *tetro);
void drop_tetromino(int **board, struct tetromino *tetro);
void lock_tetromino(int **board, struct tetromino *tetro);
int clear_lines(int **board, int y1);
int above_visible_board(struct tetromino *tetro);
void update_queue(struct tetromino_queue *queue);
void init_game(struct tetris *game, int seed);
void init_stats(struct statistics *stats);
#endif