Index

ncurses-minesweeper / 9e98a79

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
1212 Sep 2020 16:199e98a79Create game loop and page structureJosh Stockin1810G

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

text/plain3532 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";
26
27const char *title_screen_buttons[4] = {"PLAY", "OPTIONS", "HELP", "EXIT"};
28
29const char *title_screen_copyright = "Copyright (c) Joshua 'joshuas3' Stockin 2020";
30
31int draw_title_screen(game_state *state, int ch) {
32 // input handling
33 if (ch == 'j' || ch == 'J' || ch == KEY_DOWN) {
34 if (state->page_selection != 'D') {
35 state->page_selection++;
36 } else {
37 beep();
38 }
39 } else if (ch == 'k' || ch == 'K' || ch == KEY_UP) {
40 if (state->page_selection != 'A') {
41 state->page_selection--;
42 } else {
43 beep();
44 }
45 } else if (ch == 10 || ch == ' ' || ch == KEY_ENTER) { // enter key pressed, process
46 if (state->page_selection == 'D') { // QUIT
47 return 1;
48 }
49 }
50
51 // setup
52 attron(A_BOLD);
53
54 // draw splash screen
55 if (COLS > 130 && LINES > 18) {
56 for (int i = 0; i < 7; i++) {
57 const char *this_splash = title_screen_splash[i];
58 mvprintw(centery() - 8 + i, centerx(this_splash), this_splash);
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() - 6 + i, centerx(this_splash), this_splash);
64 }
65 } else {
66 mvprintw(centery() - 2, centerx(title_screen_splash_text), title_screen_splash_text);
67 }
68
69 // draw button inputs
70 for (int i = 0; i < 4; i++) {
71 if (state->page_selection == 'A' + i) attron(A_STANDOUT);
72 mvprintw(centery() + i, centerx(title_screen_buttons[i]), title_screen_buttons[i]);
73 if (state->page_selection == 'A' + i) attroff(A_STANDOUT);
74 }
75
76 // write copyright line @ bottom
77 attroff(A_BOLD);
78 mvprintw(LINES - 1, centerx(title_screen_copyright), title_screen_copyright);
79
80 return 0;
81}
82