Index

ncurses-minesweeper / 48ca66b

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

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

Blob @ ncurses-minesweeper / src / game / game.c

text/plain1458 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
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 10:
55 case ' ': {
56 open_cell(board);
57 check_done(board);
58 break;
59 }
60 }
61}
62