Index

ncurses-minesweeper / 48085a2

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
4918 Oct 2021 15:555abfbc6Add functionality to enter help screen during gameJosh Stockin110G

Blob @ ncurses-minesweeper / src / state.h

text/plain1488 bytesdownload raw
1/* ncurses-minesweeper Copyright (c) 2021 Joshua 'joshuas3' Stockin
2 * <https://joshstock.in>
3 * <https://git.joshstock.in/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#ifndef STATE_H
13#define STATE_H
14
15#include <stdint.h>
16#include <time.h>
17
18typedef enum DrawPage { Title, Game, Options, Help, About } DrawPage;
19typedef enum GameStatus { Waiting, Playing, Done, Kaboom } GameStatus;
20
21typedef struct game_board_cell {
22 uint8_t is_bomb : 1;
23 uint8_t flagged : 1;
24 uint8_t opened : 1;
25 uint8_t surrounding_bomb_count : 3; // maximum possible is 8, only need 3 bits
26} game_board_cell;
27
28typedef struct game_board {
29 uint8_t width;
30 uint8_t height;
31 uint16_t current_cell; // (x,y) | x = current_cell % width, y = current_cell / width
32 uint8_t mine_count;
33 uint8_t mines_left;
34 uint64_t time;
35 GameStatus status;
36 game_board_cell *cells; // heap allocated, size = width * height, position in array determines position on board
37} game_board;
38
39typedef struct game_state {
40 DrawPage page;
41 DrawPage last_page;
42 uint8_t page_selection; // character/token that determines what part of the screen (button/input) is selected
43 game_board *board;
44} game_state;
45
46#endif
47