Index

ncurses-minesweeper / 3345b60

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1312 Sep 2020 16:503345b60Add dynamic vertical displacement on title screenJosh Stockin186G

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

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