Game state is now preserved in a file

This commit is contained in:
2026-03-06 19:03:55 +01:00
parent 4c21d309e9
commit 016b1eafb5
5 changed files with 27 additions and 6 deletions
+9 -3
View File
@@ -3,6 +3,7 @@
#include <math.h>
#include <raylib.h>
#include <stdbool.h>
#include <stdio.h>
static bool is_dragging;
static Vector2 drag_start_pos;
@@ -55,15 +56,20 @@ void handle_mouse_input(GameState_t *game_state) {
return;
}
// TODO: Allow for infinite play
for(int y = 0; y < BOARD_HEIGHT; y++) {
for(int x = 0; x < BOARD_WIDTH; x++) {
if(game_state->board[y][x] == 2048) {
for (int y = 0; y < BOARD_HEIGHT; y++) {
for (int x = 0; x < BOARD_WIDTH; x++) {
if (game_state->board[y][x] == 2048) {
game_state->status = WON;
return;
}
}
}
FILE *f = fopen("save.dat", "wb");
if (f) {
fwrite(game_state, sizeof(GameState_t), 1, f);
fclose(f);
}
}
is_dragging = false;