Index

ncurses-minesweeper / 761b7f1

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
3330 Sep 2020 15:27868e8dfUpdate Help screen messageJosh Stockin11210G

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

text/plain2657 bytesdownload raw
1/* ncurses-minesweeper Copyright (c) 2020 Joshua 'joshuas3' Stockin
2 * <https://joshstock.in>
3 * <https://github.com/JoshuaS3/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 "pages.h"
16#include "text.h"
17
18const char *help_screen_title = "HELP";
19
20const char *help_screen_info[13] = {"Minesweeper is a logic game where mines are hidden in a grid of ",
21 "squares. The object is to open all the safe squares in the shortest",
22 "time possible.",
23 "",
24 "Use the <ENTER> key or <SPACE> to select menu items or open unopened",
25 "squares. Use the arrow keys or <hjkl> to move around. Use <f> to",
26 "toggle flags on squares. Use <ENTER> or <SPACE> on a numbered square",
27 "if enough surrounding squares are flagged in order to open remaining",
28 "surrounding squares. Use <r> to reset the board and <q> to quit.",
29 "",
30 "See the [OPTIONS] screen to change game settings.",
31 "",
32 "A minimum terminal resolution of 80x20 is recommended."};
33
34const char *help_screen_back = "Back";
35
36int draw_help_screen(game_state *state, int ch) {
37 // input handling
38 switch (ch) {
39 case -1:
40 return 0;
41 case KEY_RESIZE:
42 clear();
43 break;
44 case 10:
45 case ' ':
46 case KEY_ENTER: {
47 clear();
48 state->page = Title;
49 return draw_title_screen(state, 0);
50 break;
51 }
52 case 0:
53 break;
54 default:
55 beep();
56 }
57
58 // draw help screen
59 int mid = centery();
60
61 attron(A_BOLD | COLOR_PAIR(2));
62 mvaddstr(mid - 8, centerx(help_screen_title), help_screen_title);
63 attroff(A_BOLD);
64
65 int x = centerx(help_screen_info[0]);
66 int y = mid - 6;
67 for (int i = 0; i < 13; i++) mvaddstr(y++, x, help_screen_info[i]);
68
69 attron(A_STANDOUT);
70 mvaddstr(mid + 8, centerx(help_screen_back), help_screen_back);
71 attroff(A_STANDOUT | COLOR_PAIR(2));
72
73 return 0;
74}
75