mirror of
https://codeberg.org/hkzlab/TK2048.git
synced 2025-12-25 23:12:17 +11:00
Update sources
This commit is contained in:
parent
ca3c18983b
commit
accf2c96da
3 changed files with 49 additions and 1 deletions
29
src/game_logic.c
Normal file
29
src/game_logic.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "game_logic.h"
|
||||
|
||||
static uint8_t game_grid_alpha[GRID_WIDTH * GRID_HEIGHT];
|
||||
static uint8_t game_grid_beta[GRID_WIDTH * GRID_HEIGHT];
|
||||
|
||||
static uint8_t *front_grid = game_grid_alpha;
|
||||
static uint8_t *back_grid = game_grid_beta;
|
||||
|
||||
void swap_grids(void);
|
||||
|
||||
void swap_grids(void) {
|
||||
uint8_t *temp = front_grid;
|
||||
|
||||
front_grid = back_grid;
|
||||
back_grid = temp;
|
||||
}
|
||||
|
||||
uint8_t *get_current_grid(void) {
|
||||
return front_grid;
|
||||
}
|
||||
|
||||
uint8_t *step_game(step_direction dir) {
|
||||
// TODO: Update the grid state calculating the new state in the back grid
|
||||
|
||||
|
||||
swap_grids();
|
||||
|
||||
return front_grid;
|
||||
}
|
||||
19
src/game_logic.h
Normal file
19
src/game_logic.h
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef _GAME_LOGIC_HEADER_
|
||||
#define _GAME_LOGIC_HEADER_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define GRID_WIDTH 5
|
||||
#define GRID_HEIGHT 5
|
||||
|
||||
typedef enum {
|
||||
UP,
|
||||
DOWN,
|
||||
LEFT,
|
||||
RIGHT
|
||||
} step_direction;
|
||||
|
||||
uint8_t *get_current_grid(void);
|
||||
uint8_t *step_game(step_direction dir);
|
||||
|
||||
#endif /* _GAME_LOGIC_HEADER_ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue