Index

ncurses-minesweeper / 868e8df

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
3230 Sep 2020 15:18ac05185Add arrow key supportJosh Stockin110G

Blob @ ncurses-minesweeper / src / main.c

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