Index

ncurses-minesweeper / e935e96

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

text/plain1419 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
17int draw(game_state *state, int ch) {
18 int ret = 0;
19 switch (state->page) {
20 case Title: {
21 ret = draw_title_screen(state, ch);
22 break;
23 }
24 case Game: {
25 ret = draw_game(state, ch);
26 break;
27 }
28 case Options: {
29 ret = draw_options_screen(state, ch);
30 break;
31 }
32 case Help: {
33 ret = draw_help_screen(state, ch);
34 break;
35 }
36 default:
37 return 1;
38 }
39
40 if (ch != -1) mvprintw(LINES - 1, 0, "%04i", ch); // print most recent character press
41 mvprintw(LINES - 1, COLS - 7, "%03ix%03i", COLS, LINES); // print screen resolution
42
43 refresh();
44 return ret;
45}
46
47void draw_loop(game_state *state) {
48 int ch = 0;
49 while ((ch = getch())) {
50 if (draw(state, ch)) break; // break loop on non-zero return
51 }
52}
53