2021-11-15 08:57:27 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2021-12-14 17:56:37 +00:00
|
|
|
#include <stdbool.h>
|
2021-11-15 08:57:27 +00:00
|
|
|
|
|
|
|
#ifndef HEADER_2048
|
|
|
|
#define HEADER_2048
|
|
|
|
|
2021-12-27 18:14:44 +00:00
|
|
|
#define max(a,b) \
|
|
|
|
({ __typeof__ (a) _a = (a); \
|
|
|
|
__typeof__ (b) _b = (b); \
|
|
|
|
_a > _b ? _a : _b; })
|
|
|
|
|
2021-11-15 08:57:27 +00:00
|
|
|
typedef enum Direction {
|
2021-11-15 10:00:37 +00:00
|
|
|
NoDirection,
|
|
|
|
Up,
|
|
|
|
Down,
|
|
|
|
Right,
|
|
|
|
Left
|
2021-11-15 08:57:27 +00:00
|
|
|
} Direction;
|
|
|
|
|
|
|
|
typedef struct Game
|
|
|
|
{
|
|
|
|
uint32_t score;
|
2021-11-15 21:20:16 +00:00
|
|
|
size_t field_size_x, field_size_y;
|
2021-11-15 08:57:27 +00:00
|
|
|
uint16_t **field;
|
2021-12-14 17:56:37 +00:00
|
|
|
bool game_over;
|
2021-12-14 20:06:42 +00:00
|
|
|
bool won;
|
2021-11-15 08:57:27 +00:00
|
|
|
} Game;
|
|
|
|
|
2021-11-15 21:20:16 +00:00
|
|
|
Game game_init(size_t field_size_x, size_t field_size_y);
|
2021-12-14 17:56:37 +00:00
|
|
|
void game_move(Game *game, Direction direction);
|
2021-12-24 13:02:00 +00:00
|
|
|
void game_destroy(Game *game);
|
2021-11-15 08:57:27 +00:00
|
|
|
|
|
|
|
#endif
|