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

text/plain1033 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 <stdlib.h>
13
14#include "../state.h"
15#include "../time.h"
16
17void reset_board(game_board *board) {
18 board->status = Waiting;
19 board->mines_left = board->mine_count;
20 board->time = time_us();
21 if (board->cells != NULL) free(board->cells);
22 board->cells = calloc(board->width * board->height, sizeof(game_board_cell));
23 for (int i = 0; i < board->width * board->height; i++) {
24 game_board_cell *cell = &board->cells[i];
25 cell->is_bomb = 0;
26 cell->flagged = 0;
27 cell->opened = 0;
28 cell->surrounding_bomb_count = 0;
29 }
30}
31