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 | #ifndef STATE_H |
13 | #define STATE_H |
14 |
|
15 | #include <stdint.h> |
16 | #include <time.h> |
17 |
|
18 | typedef enum DrawPage { Title, Game, Options, Help } DrawPage; |
19 | typedef enum GameStatus { Waiting, Playing, Done, Kaboom } GameStatus; |
20 |
|
21 | typedef 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 |
|
28 | typedef 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 |
|
39 | typedef struct game_state { |
40 | DrawPage page; |
41 | uint8_t page_selection; // character/token that determines what part of the screen (button/input) is selected |
42 | game_board *board; |
43 | } game_state; |
44 |
|
45 | #endif |
46 |
|