Index

ncurses-minesweeper / 7eb2a2e

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 / title.c

text/plain4904 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
18// clang-format off
19const char *title_screen_splash[7] = {
20 ":::: :::: ::::::::::: :::: ::: :::::::::: :::::::: ::: ::: :::::::::: :::::::::: ::::::::: :::::::::: ::::::::: ",
21 "+:+:+: :+:+:+ :+: :+:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:",
22 "+:+ +:+:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+",
23 "+#+ +:+ +#+ +#+ +#+ +:+ +#+ +#++:++# +#++:++#++ +#+ +:+ +#+ +#++:++# +#++:++# +#++:++#+ +#++:++# +#++:++#: ",
24 "+#+ +#+ +#+ +#+ +#+#+# +#+ +#+ +#+ +#+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+",
25 "#+# #+# #+# #+# #+#+# #+# #+# #+# #+#+# #+#+# #+# #+# #+# #+# #+# #+#",
26 "### ### ########### ### #### ########## ######## ### ### ########## ########## ### ########## ### ###"};
27const char *title_screen_splash_small[5] = {
28 " __ ___ ____ _ __ ______ _____ _ __ ______ ______ ____ ______ ____ ",
29 " / |/ // _// | / // ____// ___/| | / // ____// ____// __ \\ / ____// __ \\",
30 " / /|_/ / / / / |/ // __/ \\__ \\ | | /| / // __/ / __/ / /_/ // __/ / /_/ /",
31 " / / / /_/ / / /| // /___ ___/ / | |/ |/ // /___ / /___ / ____// /___ / _, _/ ",
32 "/_/ /_//___//_/ |_//_____/ /____/ |__/|__//_____//_____//_/ /_____//_/ |_| "};
33// clang-format on
34
35const char *title_screen_splash_text = "MINESWEEPER";
36const char *title_screen_buttons[4] = {"PLAY", "OPTIONS", "HELP", "EXIT"};
37const char *title_screen_copyright = "Copyright (c) Joshua 'joshuas3' Stockin 2020";
38
39int draw_title_screen(game_state *state, int ch) {
40 switch (ch) {
41 case -1:
42 return 0;
43 case 'j':
44 case 'J': {
45 if (state->page_selection != 3) {
46 state->page_selection++;
47 } else
48 beep();
49 break;
50 }
51 case 'k':
52 case 'K': {
53 if (state->page_selection != 0) {
54 state->page_selection--;
55 } else
56 beep();
57 break;
58 }
59 case KEY_RESIZE:
60 clear();
61 break;
62 case 10:
63 case ' ':
64 case KEY_ENTER: {
65 clear();
66 switch (state->page_selection) {
67 case 0: {
68 state->page = Game;
69 state->page_selection = 0;
70 return draw_game(state, 0);
71 }
72 case 1: {
73 state->page = Options;
74 state->page_selection = 0;
75 return draw_options_screen(state, 0);
76 }
77 case 2: { // HELP
78 state->page = Help;
79 return draw_help_screen(state, 0);
80 }
81 case 3: { // QUIT
82 return 1;
83 }
84 }
85 break;
86 }
87 case 0:
88 break;
89 default:
90 beep();
91 }
92
93 int vdisplace = 0;
94
95 // draw splash screen
96 attron(A_BOLD | COLOR_PAIR(5));
97 if (COLS > 130 && LINES > 18) {
98 for (int i = 0; i < 7; i++) {
99 const char *this_splash = title_screen_splash[i];
100 mvprintw(centery() - 6 + i, centerx(this_splash), this_splash);
101 vdisplace = 2;
102 }
103 } else if (COLS > 85 && LINES > 14) {
104 for (int i = 0; i < 5; i++) {
105 const char *this_splash = title_screen_splash_small[i];
106 mvprintw(centery() - 5 + i, centerx(this_splash), this_splash);
107 vdisplace = 1;
108 }
109 } else {
110 mvprintw(centery() - 3, centerx(title_screen_splash_text), title_screen_splash_text);
111 vdisplace = -1;
112 }
113
114 // draw button inputs
115 for (int i = 0; i < 4; i++) {
116 if (state->page_selection == i) attron(A_STANDOUT);
117 mvprintw(centery() + i + vdisplace, centerx(title_screen_buttons[i]), title_screen_buttons[i]);
118 if (state->page_selection == i) attroff(A_STANDOUT);
119 }
120 attroff(A_BOLD);
121
122 // write copyright line @ bottom
123 mvprintw(LINES - 1, centerx(title_screen_copyright), title_screen_copyright);
124
125 attroff(COLOR_PAIR(5));
126
127 return 0;
128}
129