Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement a Minesweeper Program in C language

Shulou Source: shulou.com Published: 2022-06-01 01:49:04 10月02日 Update

This article introduces the relevant knowledge of "how to implement a minesweeping program in C language". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The main functions in the whole game design are:

1. Initialize the mine chessboard and display the chessboard

2. Chessboard printing function

3. Realization of minesweeping function.

4. Main function of the game

You can change the size of the chessboard, the number of mines, and the range of minefree areas displayed in the macro definition.

Don't talk nonsense and go straight to the code: (unoptimized, please forgive me)

# ifndef _ MINE_H__ # define _ MINE_H__ # define LINES 11 / / rows of the chessboard # define ROWS 11 / / columns of the chessboard # define mine_MAX 10 / / number of mines # define EAXY 3 / / simple display range # define COMMON 2 / / normal display range # define DIFFICULT 1 / / difficult display range enum op {EXIT, PLAY} Void game (char mine [LINES] [ROWS], char text [LINES] [ROWS], int lines,int rows); / / basic game implementation function void init_mine (char mine [LINES] [ROWS], char text [LINES] [ROWS], int lines,int rows); / / initialize the chessboard function void play_EAXY_game (char mine [LINES] [ROWS], char text [LINES] [ROWS]) / / simple game function void play_COMMON_game (char mine [LINES] [ROWS], char text [LINES] [ROWS]); / / ordinary game function void play_DIFFICULT_game (char mine [LINES] [ROWS], char text [LINES] [ROWS]); / / difficult game function void mine_EAXY_sweep (char mine [LINES] [ROWS], char text [LINES] [ROWS]) / / simple minesweeping to achieve void mine_COMMON_sweep (char mine [LINES] [ROWS], char text [LINES] [ROWS]); / / ordinary minesweeping to achieve void mine_DIFFICULT_sweep (char mine [LINES] [ROWS], char text [LINES] [ROWS]); / / difficult minesweeping to achieve void print (char tab [LINES] [ROWS]) / / print chessboard # endif#include # include "mine.h" # include # include void init_mine (char mine [LINES] [ROWS], char text [LINES] [ROWS], int lines,int rows) / / initialize the display of chessboard and mineboard {int i; int j; int a; int b; int count=0; for (iTun1; I)

Tags: Chessboard function minesweeping ordinary difficult input range success number used quantity time selection program language content coordinates more knowledge process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology NVidia Xiaomi Shulou Tech Info MySQL