Brick Game v1.0
Implementation of the game Tetris in the C programming language with a terminal user interface.
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1
3
4#ifndef BRICK_GAME_V1_0_BRICK_GAME_TETRIS_GAME_COMMON_H_
5#define BRICK_GAME_V1_0_BRICK_GAME_TETRIS_GAME_COMMON_H_
6
7#include <stdlib.h>
8
9#include "../game.h"
10
12static inline PieceType generate_piece(void) {
13 return rand() % PIECE_TYPE_COUNT;
14}
15
21static inline void transition_state(GameData *game_data, GameState new_state) {
22 game_data->state = new_state;
23 game_data->timer = 0;
24}
25
31static inline void reset_game_data(GameData *game_data) {
32 // don't reset the top score
33 int top_score = game_data->top_score;
34 *game_data = (GameData) {0};
35 game_data->top_score = top_score;
36
37 game_data->played_piece.x = -4;
38 game_data->played_piece.y = -4;
39}
40
41#endif // BRICK_GAME_V1_0_BRICK_GAME_TETRIS_GAME_UTILS_H_
static PieceType generate_piece(void)
Generate a random piece type.
Definition common.h:12
GameState
Enumeration of all states of the game's Finite State Machine.
Definition game.h:19
PieceType
Possible piece types.
Definition piece.h:23
A structure containing all data about the current game session.
Definition game.h:116
static void reset_game_data(GameData *game_data)
Reset game state between play sessions.
Definition common.h:31
int top_score
Current highscore.
Definition game.h:154
GameState state
Current state of the game's state machine.
Definition game.h:118
PlayedPiece played_piece
Information about the currently played piece.
Definition game.h:126
static void transition_state(GameData *game_data, GameState new_state)
Transition the current game state to the given one.
Definition common.h:21
int timer
Counter used for timing different things.
Definition game.h:141
int x
X offset of the upper left corner of the piece data.
Definition piece.h:36
int y
Y offset of the upper left corner of the piece data.
Definition piece.h:38