#include "game.h" #include "color.h" #include "utilities.h" #include void draw_line(int color, char *text, size_t length) { int width = getmaxx(stdscr); int height = getmaxy(stdscr) - 1; char footer[width + 1]; memset(footer, ' ', width); footer[width] = 0; //Display: attron(COLOR_PAIR(color)); mvprintw(height, 0, footer); strncpy(footer, text, length); mvprintw(height, 0, footer); } void draw_line_info(int steps_taken, int steps_remaining) { char buffer[getmaxx(stdscr) + 1]; int length = sprintf(buffer, "%d/%d", steps_taken, steps_remaining); draw_line(CI_LINE_INFO, buffer, length); } void draw_line_win() { char buffer[getmaxx(stdscr) + 1]; int length = sprintf(buffer, "\u2714 Win! \u263A"); draw_line(CI_LINE_SUCCESS, buffer, length); } int get_command(char prompt, char *command) { int width = getmaxx(stdscr); int height = getmaxy(stdscr) - 1; char line[width + 1]; memset(line, ' ', width); line[width] = 0; attron(COLOR_PAIR(CI_LINE_CMD)); curs_set(1); char *current = command; *(current++) = prompt; *current = 0; while (1) { mvaddstr(height, 0, line); mvaddstr(height, 0, command); refresh(); wchar_t c = wgetch(stdscr); if (c == KEY_BACKSPACE) { current--; *current = 0; if (current == command) { curs_set(0); return 0; } } else if (c == 10) { curs_set(0); return 1; } else { *(current++) = c; *current = 0; } } } struct game_state *create_game_state(struct maze *maze) { struct maze_display *display = malloc(sizeof(struct maze_display)); display->maze_pos.x = 0; display->maze_pos.y = 0; display->maze = maze; display->player_pos = maze->starting_point; display->display_player_path = true; display->visible = false; //Signs int signs_length = sizeof_2d(maze->width, maze->height, sizeof(int)); display->signs = malloc(signs_length); memset(display->signs, (int)RS_NONE, signs_length); init2d((void **)display->signs, maze->width, maze->height, sizeof(int)); display->signs[display->player_pos.x][display->player_pos.y] = RS_PATH; struct game_state *state = malloc(sizeof(struct game_state)); state->display = display; state->center = false; state->win = false; state->steps_taken = 0; state->new_maze_pos = display->maze_pos; state->new_player_pos = display->player_pos; return state; } struct array { int width; int height; int *arr; };