Files
2048/src/2048.h
2022-07-26 15:46:32 -04:00

57 lines
1.1 KiB
C

#ifndef __2048_H__
#define __2048_H__
#include <stdbool.h>
#include <curses.h>
#include <notcurses/nckeys.h>
#include <notcurses/notcurses.h>
typedef unsigned int uint;
struct _2048_cell {
// posiiton
uint y;
uint x;
// 0 = empty
uint level;
};
struct _2048_board {
struct _2048_cell *cells[4][4];
// 1 = running; 0 = not running;
bool state;
};
enum _2048_direction {
_2048_left,
_2048_right,
_2048_up,
_2048_down
};
enum _2048_gameState {
_2048_normal,
_2048_reached,
_2048_cant_move
};
struct _2048_board *_2048_init_board();
struct _2048_cell *_2048_init_cell(uint y, uint x);
void _2048_destroy_board(struct _2048_board *board);
void _2048_draw_cell(struct _2048_cell *cell, struct ncplane *plane, uint y, uint x);
void _2048_draw_board(struct _2048_board *board, struct ncplane *plane, uint py, uint px);
void _2048_place_random(struct _2048_board *board);
bool _2048_compress(struct _2048_board *board);
bool _2048_merge(struct _2048_board *board);
bool _2048_move(struct _2048_board *board, enum _2048_direction dir);
enum _2048_gameState _2048_determineState(struct _2048_board *board);
#endif