From afb392b548b07e724ceefdd209b12e759b327794 Mon Sep 17 00:00:00 2001 From: Judro Date: Mon, 25 Nov 2024 11:49:43 +0100 Subject: [PATCH] format code --- src/controls.c | 2 +- src/display.c | 5 +---- src/game.h | 17 ++++++++--------- src/menu.c | 2 +- src/mines.c | 18 +++++++++--------- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/controls.c b/src/controls.c index c8de666..f40147f 100644 --- a/src/controls.c +++ b/src/controls.c @@ -37,7 +37,7 @@ int cmove(GameInstance g, WINDOW *window) { case 'q': return -1; case 'f': - flag_cell(g); + flag_cell(g); case 's': unveil_cell(g); case 'e': diff --git a/src/display.c b/src/display.c index d3ab41b..a926c66 100644 --- a/src/display.c +++ b/src/display.c @@ -3,8 +3,6 @@ #include #include - - char *generate_top_margin(unsigned int l) { if (l > 1000) l = 1; @@ -35,8 +33,7 @@ void print_left_margin(unsigned int terminal_x, unsigned int game_x) { free(lm); } -void print_header(GameView view, unsigned int terminal_x, - unsigned int game_x) { +void print_header(GameView view, unsigned int terminal_x, unsigned int game_x) { print_left_margin(terminal_x, game_x); printw("│"); int mtw = 15; diff --git a/src/game.h b/src/game.h index a84c12e..c826ff5 100644 --- a/src/game.h +++ b/src/game.h @@ -14,7 +14,7 @@ typedef enum GameState { Lost, } GameState; -typedef enum CellType { +typedef enum CellType { UNTOUCHED, UNVEILED, FALSE_FLAG, @@ -30,15 +30,14 @@ typedef enum CellType { EIGHT, } CellType; - typedef struct GameView { - CellType *cells; - Cord player; - unsigned width; - unsigned height; - GameState state; - unsigned mines; - time_t time; + CellType *cells; + Cord player; + unsigned width; + unsigned height; + GameState state; + unsigned mines; + time_t time; } *GameView; GameState game_state(GameInstance); diff --git a/src/menu.c b/src/menu.c index 37b6a73..21e8474 100644 --- a/src/menu.c +++ b/src/menu.c @@ -110,7 +110,7 @@ GameInstance select_mode(unsigned int terminal_width, if (ret == -1) return NULL; if (menu.selected == 1) { - last_selected = menu.pos; + last_selected = menu.pos; switch (menu.pos) { case 0: return createGameInstance(20, 5, 7); diff --git a/src/mines.c b/src/mines.c index 35ba353..508c917 100644 --- a/src/mines.c +++ b/src/mines.c @@ -35,7 +35,7 @@ void print_game(GameInstance game, WINDOW *window) { erase(); print_top_margin(getmaxy(window), field_height(game) + 2); GameView view; - if(game_state(game) == Lost) { + if (game_state(game) == Lost) { view = createViewGameover(game); } else { view = createView(game); @@ -64,16 +64,16 @@ int main(int argc, char *argv[]) { validate_flags(game); if (cmove(game, window) == -1) break; - switch (game_state(game)){ - case Playing: - break; - case Lost: - case Won: + switch (game_state(game)) { + case Playing: + break; + case Lost: + case Won: print_game(game, window); while (1) { - if (cmove(game, window) == -1) - goto new_game; - limit_fps(); + if (cmove(game, window) == -1) + goto new_game; + limit_fps(); } } limit_fps();