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