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 / game / game.c

text/plain1444 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
14#include "../state.h"
15#include "constrain_movement.h"
16#include "done.h"
17#include "flag.h"
18#include "nearest_cells.h"
19#include "new.h"
20#include "open.h"
21#include "reset.h"
22
23
24void game(game_state *state, int ch) {
25 game_board *board = state->board;
26 switch (ch) {
27 case 0:
28 case 'r':
29 case 'R': {
30 reset_board(board);
31 break;
32 }
33 case KEY_DOWN: {
34 constrain_down(board);
35 break;
36 }
37 case KEY_UP: {
38 constrain_up(board);
39 break;
40 }
41 case KEY_LEFT: {
42 constrain_left(board);
43 break;
44 }
45 case KEY_RIGHT: {
46 constrain_right(board);
47 break;
48 }
49 case 'f':
50 case 'F': {
51 flag_current_cell(board);
52 break;
53 }
54 case KEY_ENTER: {
55 open_cell(board);
56 check_done(board);
57 break;
58 }
59 }
60}
61