Index

ncurses-minesweeper / ac05185

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
2417 Sep 2020 22:4163b24cbFix copyright disclaimerJosh Stockin111G

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

text/plain2504 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[11] = {"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 the spacebar to select menu items or open",
25 "unopened squares. Use <hjkl> to move around. Use <f> to toggle flags",
26 "on squares. Use <SPACE> on a numbered square if enough surrounding",
27 "squares are flagged in order to open remaining surrounding squares.",
28 "Use <r> to reset the board and <q> to quit.",
29 "",
30 "A minimum terminal resolution of 80x20 is recommended."};
31
32const char *help_screen_back = "Back";
33
34int draw_help_screen(game_state *state, int ch) {
35 // input handling
36 switch (ch) {
37 case -1:
38 return 0;
39 case KEY_RESIZE:
40 clear();
41 break;
42 case 10:
43 case ' ':
44 case KEY_ENTER: {
45 clear();
46 state->page = Title;
47 return draw_title_screen(state, 0);
48 break;
49 }
50 case 0:
51 break;
52 default:
53 beep();
54 }
55
56 // draw help screen
57 int mid = centery();
58
59 attron(A_BOLD | COLOR_PAIR(2));
60 mvaddstr(mid - 7, centerx(help_screen_title), help_screen_title);
61 attroff(A_BOLD);
62
63 int x = centerx(help_screen_info[0]);
64 int y = mid - 5;
65 for (int i = 0; i < 11; i++) mvaddstr(y++, x, help_screen_info[i]);
66
67 attron(A_STANDOUT);
68 mvaddstr(mid + 7, centerx(help_screen_back), help_screen_back);
69 attroff(A_STANDOUT | COLOR_PAIR(2));
70
71 return 0;
72}
73