Brick Game v1.0
Implementation of the game Tetris in the C programming language with a terminal user interface.
Loading...
Searching...
No Matches
game.h File Reference

Main entry point of the library. More...

#include <stdbool.h>
#include "field.h"
#include "piece.h"
+ Include dependency graph for game.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Inputs
 A bitfield describing active user inputs. More...
 
struct  FilledLines
 A list of indices of lines that are detected to be full. More...
 
struct  GameData
 A structure containing all data about the current game session. More...
 

Macros

#define MAX_LEVEL   10
 The maximum level the player can reach.
 

Typedefs

typedef struct GameData GameData
 A structure containing all data about the current game session.
 

Enumerations

enum  GameState {
  START , SPAWN_START , SPAWN , MOVING ,
  ATTACHING , CLEARING , GAME_OVER
}
 Enumeration of all states of the game's Finite State Machine. More...
 

Detailed Description

Main entry point of the library.

Defines the main data structure of the game — GameData and possible operations on it.

Enumeration Type Documentation

◆ GameState

enum GameState

Enumeration of all states of the game's Finite State Machine.

Enumerator
START 

Start screen of the game.

Transitions to @ref SPAWN_START when the user action @ref Start is
received. 
SPAWN_START 

Spawn a random first piece and generate a random next piece.

Different from @ref SPAWN because the spawned piece is random and not the
next piece.

Entered from @ref START and @ref GAME_OVER for the first spawn of the
game.

Transitions to @ref MOVING after the piece has been spawned. 
SPAWN 

Spawn the next piece and generate a new random next piece.

Applies spawn delay proportional to the distance of the attached piece
from the ground. The higher the piece was attached, the longer the delay,
to provide the player with ample time to think when they are close
to losing.

Transitions to @ref GAME_OVER if there is not enough space for the spawned
piece.

Otherwise, transitions to @ref MOVING after the piece has been spawned. 
MOVING 

Main state of the game, the player is in control of the piece.

The played piece is rotated and moved sideways or downwards according to
player's inputs.

The piece is also automatically moved downwards at fixed intervals. The
intervals get progressively shorter at higher levels.

Transitions to @ref ATTACHING when the piece touches the ground. 
ATTACHING 

The played piece is attached to the field.

Transitions to @ref CLEARING if the attached piece completes one or more
lines.

Otherwise, transitions to @ref SPAWN. 
CLEARING 

Full lines are cleared and points are awarded.

Plays a quick animation of the lines clearing and moves the lines above
down.

Points are awarded based on amount of lines cleared according to the table
below:

| Lines Cleared | Points Awarded |
| ------------- | -------------- |
| 1             | 100            |
| 2             | 300            |
| 3             | 700            |
| 4             | 1500           |

Transitions to @ref SPAWN 
GAME_OVER 

Game over screen of the game.

Transitions to @ref SPAWN_START when the user action @ref Start is
received.