Index

ncurses-minesweeper / 9c8d69c

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
2117 Sep 2020 21:34d83acc5Rewrite and finish game and renderer codeJosh Stockin1305G

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

text/plain2412 bytesdownload raw
1/* ncurses-minesweeper Copyright (c) 2020 Joshua 'joshuas3' Stockin
2 * <https://joshstock.in>
3 * <https://github.com/JoshuaS3/lognestmonster>
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[10] = {"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 <g> on a numbered square if enough surrounding",
27 "squares are flagged in order to open remaining surrounding squares.",
28 "",
29 "A minimum terminal resolution of 80x20 is recommended."};
30
31const char *help_screen_back = "Back";
32
33int draw_help_screen(game_state *state, int ch) {
34 // input handling
35 switch (ch) {
36 case -1:
37 return 0;
38 case KEY_RESIZE:
39 clear();
40 break;
41 case 10:
42 case ' ':
43 case KEY_ENTER: {
44 clear();
45 state->page = Title;
46 return draw_title_screen(state, 0);
47 break;
48 }
49 case 0:
50 break;
51 default:
52 beep();
53 }
54
55 // draw help screen
56 int mid = centery();
57
58 attron(A_BOLD | COLOR_PAIR(2));
59 mvaddstr(mid - 7, centerx(help_screen_title), help_screen_title);
60 attroff(A_BOLD);
61
62 int x = centerx(help_screen_info[0]);
63 int y = mid - 5;
64 for (int i = 0; i < 10; i++) mvaddstr(y++, x, help_screen_info[i]);
65
66 attron(A_STANDOUT);
67 mvaddstr(mid + 7, centerx(help_screen_back), help_screen_back);
68 attroff(A_STANDOUT | COLOR_PAIR(2));
69
70 return 0;
71}
72