Index

ncurses-minesweeper / d5da239

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1712 Sep 2020 19:43d5da239Create Options pageJosh Stockin150G

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

text/plain3917 bytesdownload raw
1#include <ncurses.h>
2
3#include "../state.h"
4#include "pages.h"
5#include "text.h"
6
7// clang-format off
8const char *title_screen_splash[7] = {
9 ":::: :::: ::::::::::: :::: ::: :::::::::: :::::::: ::: ::: :::::::::: :::::::::: ::::::::: :::::::::: ::::::::: ",
10 "+:+:+: :+:+:+ :+: :+:+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+: :+:",
11 "+:+ +:+:+ +:+ +:+ :+:+:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+",
12 "+#+ +:+ +#+ +#+ +#+ +:+ +#+ +#++:++# +#++:++#++ +#+ +:+ +#+ +#++:++# +#++:++# +#++:++#+ +#++:++# +#++:++#: ",
13 "+#+ +#+ +#+ +#+ +#+#+# +#+ +#+ +#+ +#+#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+",
14 "#+# #+# #+# #+# #+#+# #+# #+# #+# #+#+# #+#+# #+# #+# #+# #+# #+# #+#",
15 "### ### ########### ### #### ########## ######## ### ### ########## ########## ### ########## ### ###"};
16const char *title_screen_splash_small[5] = {
17 " __ ___ ____ _ __ ______ _____ _ __ ______ ______ ____ ______ ____ ",
18 " / |/ // _// | / // ____// ___/| | / // ____// ____// __ \\ / ____// __ \\",
19 " / /|_/ / / / / |/ // __/ \\__ \\ | | /| / // __/ / __/ / /_/ // __/ / /_/ /",
20 " / / / /_/ / / /| // /___ ___/ / | |/ |/ // /___ / /___ / ____// /___ / _, _/ ",
21 "/_/ /_//___//_/ |_//_____/ /____/ |__/|__//_____//_____//_/ /_____//_/ |_| "};
22// clang-format on
23
24const char *title_screen_splash_text = "MINESWEEPER";
25const char *title_screen_buttons[4] = {"PLAY", "OPTIONS", "HELP", "EXIT"};
26const char *title_screen_copyright = "Copyright (c) Joshua 'joshuas3' Stockin 2020";
27
28int draw_title_screen(game_state *state, int ch) {
29 // input handling
30 if (ch == 'j' || ch == 'J') {
31 if (state->page_selection != 3) {
32 state->page_selection++;
33 } else {
34 beep();
35 }
36 } else if (ch == 'k' || ch == 'K') {
37 if (state->page_selection != 0) {
38 state->page_selection--;
39 } else {
40 beep();
41 }
42 } else if (ch == 10 || ch == ' ' || ch == KEY_ENTER) { // enter key pressed, process
43 switch (state->page_selection) {
44 case 1: {
45 state->page = Options;
46 state->page_selection = 0;
47 return draw_options_screen(state, 0);
48 }
49 case 2: { // HELP
50 state->page = Help;
51 return draw_help_screen(state, 0);
52 }
53 case 3: { // QUIT
54 return 1;
55 }
56 }
57 }
58
59 // setup
60 attron(A_BOLD);
61
62 // draw splash screen
63 int vdisplace = 0;
64 if (COLS > 130 && LINES > 18) {
65 for (int i = 0; i < 7; i++) {
66 const char *this_splash = title_screen_splash[i];
67 mvprintw(centery() - 6 + i, centerx(this_splash), this_splash);
68 vdisplace = 2;
69 }
70 } else if (COLS > 85 && LINES > 14) {
71 for (int i = 0; i < 5; i++) {
72 const char *this_splash = title_screen_splash_small[i];
73 mvprintw(centery() - 5 + i, centerx(this_splash), this_splash);
74 vdisplace = 1;
75 }
76 } else {
77 mvprintw(centery() - 3, centerx(title_screen_splash_text), title_screen_splash_text);
78 vdisplace = -1;
79 }
80
81 // draw button inputs
82 for (int i = 0; i < 4; i++) {
83 if (state->page_selection == i) attron(A_STANDOUT);
84 mvprintw(centery() + i + vdisplace, centerx(title_screen_buttons[i]), title_screen_buttons[i]);
85 if (state->page_selection == i) attroff(A_STANDOUT);
86 }
87
88 // write copyright line @ bottom
89 attroff(A_BOLD);
90 mvprintw(LINES - 1, centerx(title_screen_copyright), title_screen_copyright);
91
92 return 0;
93}
94