Index

ncurses-minesweeper / bec4c7f

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1512 Sep 2020 18:10bec4c7fCreate Help screenJosh Stockin1470G

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

text/plain1741 bytesdownload raw
1#include <ncurses.h>
2
3#include "../state.h"
4#include "text.h"
5
6#include "title.h"
7
8const char *help_screen_title = "HELP";
9
10const char *help_screen_info[10] = {"Minesweeper is a logic game where mines are hidden in a grid of ",
11 "squares. The object is to open all the safe squares in the shortest",
12 "time possible.",
13 "",
14 "Use the <ENTER> key or the spacebar to select menu items or open",
15 "unopened squares. Use <hjkl> to move around. Use <f> to toggle flags",
16 "on squares. Use <g> on a numbered square if enough surrounding",
17 "squares are flagged in order to open remaining surrounding squares.",
18 "",
19 "A minimum terminal resolution of 80x20 is recommended."};
20
21const char *help_screen_back = "Back";
22
23int draw_help_screen(game_state *state, int ch) {
24 // input handling
25 if (ch == 10 || ch == ' ' || ch == KEY_ENTER) {
26 state->page = Title;
27 return draw_title_screen(state, 0);
28 } else if (ch == 'k' || ch == 'K' || ch == 'j' || ch == 'J')
29 beep();
30
31 // draw help screen
32 int mid = centery();
33
34 attron(A_BOLD);
35 mvaddstr(mid - 7, centerx(help_screen_title), help_screen_title);
36 attroff(A_BOLD);
37
38 int x = centerx(help_screen_info[0]);
39 int y = mid - 5;
40 for (int i = 0; i < 10; i++) mvaddstr(y++, x, help_screen_info[i]);
41
42 attron(A_STANDOUT);
43 mvaddstr(mid + 7, centerx(help_screen_back), help_screen_back);
44 attroff(A_STANDOUT);
45
46 return 0;
47}
48