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->current_cell = board->width / 2; |
37 | board->cells = calloc(board->width * board->height, sizeof(game_board_cell)); |
38 | reset_board(board); |
39 |
|
40 | initscr(); |
41 | timeout(0); |
42 | noecho(); |
43 | cbreak(); |
44 |
|
45 | if (!has_colors()) { |
46 | printf("Your terminal doesn't support color.\n"); |
47 | endwin(); |
48 | return 1; |
49 | } |
50 | init_colorpairs(); |
51 | curs_set(0); |
52 |
|
53 | draw(state, 0); // draw initial window |
54 | draw_loop(state); // enter control input loop |
55 |
|
56 | endwin(); |
57 |
|
58 | free(board->cells); |
59 | free(board); |
60 | free(state); |
61 |
|
62 | return 0; |
63 | } |
64 |
|