Index

ncurses-minesweeper / 48085a2

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
4817 Oct 2021 18:26c10793dUpdate repository endpoint in comment blocksJosh Stockin111G

Blob @ ncurses-minesweeper / src / main.c

text/plain1479 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#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
21int main(void) {
22 initscr();
23 if (!has_colors()) {
24 endwin();
25 printf("Your terminal doesn't support color.\n");
26 return 1;
27 }
28
29 game_state *state = calloc(1, sizeof(game_state));
30 state->page = Title;
31 state->page_selection = 0;
32 game_board *board = calloc(1, sizeof(game_board));
33 state->board = board;
34 board->status = Waiting;
35 board->width = 30;
36 board->height = 16;
37 board->mine_count = 99;
38 board->mines_left = 99;
39 board->current_cell = board->width / 2;
40 board->cells = NULL;
41 reset_board(board);
42
43 timeout(30);
44 noecho();
45 cbreak();
46 keypad(stdscr, TRUE);
47
48 init_colorpairs();
49 curs_set(0);
50
51 draw(state, 0); // draw initial window
52 draw_loop(state); // enter control input loop
53
54 endwin();
55
56 free(board->cells);
57 free(board);
58 free(state);
59
60 return 0;
61}
62