Index

ncurses-minesweeper / 48085a2

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
4918 Oct 2021 15:555abfbc6Add functionality to enter help screen during gameJosh Stockin152G

Blob @ ncurses-minesweeper / src / draw / help.c

text/plain1727 bytesdownload raw
1/* ncurses-minesweeper Copyright (c) 2021 Joshua 'joshuas3' Stockin
2 * <https://joshstock.in>
3 * <https://git.joshstock.in/ncurses-minesweeper>
4 *
5 * This software is licensed and distributed under the terms of the MIT License.
6 * See the MIT License in the LICENSE file of this project's root folder.
7 *
8 * This comment block and its contents, including this disclaimer, MUST be
9 * preserved in all copies or distributions of this software's source.
10 */
11
12#include <ncurses.h>
13
14#include "../state.h"
15#include "../strings.h"
16#include "pages.h"
17#include "text.h"
18
19int draw_help_screen(game_state *state, int ch) {
20 // input handling
21 switch (ch) {
22 case -1:
23 return 0;
24 case KEY_RESIZE:
25 clear();
26 break;
27 case 10:
28 case ' ':
29 case KEY_ENTER: {
30 clear();
31 state->page = state->last_page;
32 if (state->page == Title)
33 return draw_title_screen(state, 0);
34 else if (state->page == Game)
35 return draw_game(state, -2);
36 break;
37 }
38 case 0:
39 break;
40 default:
41 beep();
42 }
43
44 // draw help screen
45 int top = centery() - (HELP_SCREEN_INFO_LEN / 2) - 3;
46 if (top < 0) top = 0;
47
48 attron(A_BOLD | COLOR_PAIR(2));
49 mvaddstr(top, centerx(help_screen_title), help_screen_title);
50 attroff(A_BOLD);
51
52 int x = centerx(help_screen_info[0]);
53 int y = top + 2;
54 for (int i = 0; i < HELP_SCREEN_INFO_LEN; i++) mvaddstr(y++, x, help_screen_info[i]);
55
56 attron(A_STANDOUT);
57 mvaddstr(top + 3 + HELP_SCREEN_INFO_LEN, centerx(help_screen_back), help_screen_back);
58 attroff(A_STANDOUT | COLOR_PAIR(2));
59
60 return 0;
61}
62