From 74ea6dc86646cee9915292d73d8c7afef01ef3e0 Mon Sep 17 00:00:00 2001 From: Sopár Adrián Date: Thu, 20 Jun 2024 09:28:14 +0200 Subject: First commit. This is mostly the state of the project as I left it around the end of 2019. --- src/game/game.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/game/game.h (limited to 'src/game/game.h') diff --git a/src/game/game.h b/src/game/game.h new file mode 100644 index 0000000..4b0de07 --- /dev/null +++ b/src/game/game.h @@ -0,0 +1,67 @@ +#ifndef H_MAZE_GAME_GAME +#define H_MAZE_GAME_GAME + +#include +#include +#include +#include "maze.h" + +enum game_res +{ + GR_MENU, + GR_QUIT +}; + +enum signs +{ + RS_NONE, + RS_SOLVE, + RS_PATH +}; + +struct maze_display +{ + struct point maze_pos; + struct point player_pos; + struct maze *maze; + enum signs **signs; + bool display_player_path; +}; + +struct game_state +{ + struct maze_display *display; + struct point new_maze_pos; + struct point new_player_pos; + int steps_taken; + bool center; + bool win; + char cmd_history[100][256]; + size_t cmd_count; + enum game_res result; +}; + +struct game_state *create_game_state(struct maze *maze); + +void draw_line_win(); + +void draw_line_info(int steps_taken, int steps_remaining); + +int get_command(char prompt, char *command); + +static inline int is_movable(struct maze_display *display, int x, int y) +{ + return display->maze->map[display->player_pos.x + x][display->player_pos.y + y] == 0; +} + +static inline struct point get_player_center(struct point player_pos) +{ + int width = getmaxx(stdscr); + int height = getmaxy(stdscr) - 1; + struct point maze_pos; + maze_pos.x = (width / 2) - player_pos.x; + maze_pos.y = (height / 2) - player_pos.y; + return maze_pos; +} + +#endif \ No newline at end of file -- cgit v1.2.3