Brick Game v1.0
Implementation of the game Tetris in the C programming language with a terminal user interface.
Loading...
Searching...
No Matches
brick_game.h
Go to the documentation of this file.
1
3
4#ifndef BRICK_GAME_V1_0_BRICK_GAME_BRICK_GAME_H_
5#define BRICK_GAME_V1_0_BRICK_GAME_BRICK_GAME_H_
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10
11#include <stdbool.h>
12
13typedef enum GameStatus {
14 GAME_STATUS_RUNNING,
15 GAME_STATUS_PAUSED,
16 GAME_STATUS_GAME_OVER,
17 GAME_STATUS_START,
18} GameStatus;
19
20#define FIELD_ROWS 20
21#define FIELD_COLS 10
22#define NEXT_ROWS 4
23#define NEXT_COLS 4
24
44
46typedef struct GameInfo {
49 int **field;
52 int **next;
54 int score;
58 int level;
60 int speed;
64 GameStatus status;
66
68struct GameInstance;
69typedef struct GameInstance GameInstance;
70
73
76
82void user_input(GameInstance *instance, UserAction action);
83
90
91#ifdef __cplusplus
92}
93#endif
94
95#endif // BRICK_GAME_V1_0_BRICK_GAME_BRICK_GAME_H_
GameInstance * game_instance_create(void)
Create a new GameInstance.
Definition lib.c:89
UserAction
A player action.
Definition brick_game.h:26
@ Action
Action button.
Definition brick_game.h:42
@ Up
Up D-pad button.
Definition brick_game.h:38
@ Left
Left D-pad button.
Definition brick_game.h:34
@ Terminate
Stop the game.
Definition brick_game.h:32
@ Down
Down D-pad button.
Definition brick_game.h:40
@ Start
Start the game.
Definition brick_game.h:28
@ Right
Right D-pad button.
Definition brick_game.h:36
@ Pause
Pause the game.
Definition brick_game.h:30
void game_instance_destroy(GameInstance *instance)
Destroy a GameInstance and release its resources.
Definition lib.c:97
Information about the current state of the game.
Definition brick_game.h:46
int high_score
The highest score ever achieved.
Definition brick_game.h:56
int ** field
20x10 Matrix of representing the game field Each cell is either 0 - empty, or 1 - filled
Definition brick_game.h:49
int score
The current score.
Definition brick_game.h:54
GameStatus status
The status of the game.
Definition brick_game.h:64
int ** next
a 4x4 Matrix representing the next piece Each cell is either 0 - empty, or 1 - filled
Definition brick_game.h:52
int level
The current level, 1 - 10.
Definition brick_game.h:58
int speed
The current speed of the game, 1 - 10.
Definition brick_game.h:60
Definition lib.c:11
GameInfo update_current_state(GameInstance *instance)
Advance the game state by one frame.
Definition lib.c:101
void user_input(GameInstance *instance, UserAction action)
Register a user input.
Definition lib.c:52