Index

ncurses-minesweeper / 34925b1

Terminal game of Minesweeper, implemented in C with ncurses.

Latest Commit

{#}TimeHashSubjectAuthor#(+)(-)GPG?
2417 Sep 2020 22:4163b24cbFix copyright disclaimerJosh Stockin111G

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

text/plain1143 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
16void constrain_up(game_board *board) {
17 if (board->current_cell >= board->width)
18 board->current_cell -= board->width;
19 else
20 beep();
21}
22
23void constrain_down(game_board *board) {
24 if (board->current_cell < board->width * (board->height - 1))
25 board->current_cell += board->width;
26 else
27 beep();
28}
29
30void constrain_left(game_board *board) {
31 if (board->current_cell % board->width > 0)
32 board->current_cell--;
33 else
34 beep();
35}
36
37void constrain_right(game_board *board) {
38 if ((board->current_cell + 1) % board->width > 0)
39 board->current_cell++;
40 else
41 beep();
42}
43