1 | /* ncurses-minesweeper Copyright (c) 2020 Joshua 'joshuas3' Stockin |
2 | * <https://joshstock.in> |
3 | * <https://github.com/JoshuaS3/lognestmonster> |
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 | #include <stdio.h> |
14 | #include <stdlib.h> |
15 |
|
16 | #include "colors.h" |
17 | #include "draw/draw.h" |
18 | #include "game/reset.h" |
19 | #include "state.h" |
20 |
|
21 | int main(void) { |
22 | printf("ncurses-minesweeper Copyright (c) Joshua 'joshuas3' Stockin 2020\n"); |
23 | printf("<https://joshstock.in>\n"); |
24 | printf("<https://github.com/JoshuaS3/ncurses-minesweeper>\n"); |
25 |
|
26 | game_state *state = calloc(1, sizeof(game_state)); |
27 | state->page = Title; |
28 | state->page_selection = 0; |
29 | game_board *board = calloc(1, sizeof(game_board)); |
30 | state->board = board; |
31 | board->status = Waiting; |
32 | board->width = 30; |
33 | board->height = 16; |
34 | board->mine_count = 99; |
35 | board->mines_left = 99; |
36 | board->cells = calloc(board->width * board->height, sizeof(game_board_cell)); |
37 | reset_board(board); |
38 |
|
39 | initscr(); |
40 | timeout(0); |
41 | noecho(); |
42 | cbreak(); |
43 |
|
44 | if (!has_colors()) { |
45 | printf("Your terminal doesn't support color.\n"); |
46 | endwin(); |
47 | return 1; |
48 | } |
49 | init_colorpairs(); |
50 | curs_set(0); |
51 |
|
52 | draw(state, 0); // draw initial window |
53 | draw_loop(state); // enter control input loop |
54 |
|
55 | endwin(); |
56 |
|
57 | free(board->cells); |
58 | free(board); |
59 | free(state); |
60 |
|
61 | return 0; |
62 | } |
63 |
|