blob: d00aaffa5d345bd350cf53ab9eb16bd0e711501f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#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;
bool visible;
};
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
|