diff options
| author | Sopár Adrián <adrian.sopar@protonmail.com> | 2024-06-20 09:28:14 +0200 |
|---|---|---|
| committer | Sopár Adrián <adrian.sopar@protonmail.com> | 2024-06-20 09:28:14 +0200 |
| commit | 74ea6dc86646cee9915292d73d8c7afef01ef3e0 (patch) | |
| tree | 9a58866f7765dad8ba56f1f40b1fa031e9d2687d /src/game/game.h | |
First commit. This is mostly the state of the project as I left it around the end of 2019.HEADmaster
Diffstat (limited to 'src/game/game.h')
| -rw-r--r-- | src/game/game.h | 67 |
1 files changed, 67 insertions, 0 deletions
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 <stdlib.h> +#include <stdbool.h> +#include <ncurses.h> +#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 |
