Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use C language to realize simple Minesweeper Game

Shulou Source: shulou.com Published: 2022-06-02 15:30:59 09月12日 Update

This article introduces the relevant knowledge of "how to use C language to achieve a simple minesweeper game". 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!

1. Construction of the main function int main () {int input = 0; do {menu (); printf ("Please choose whether or not to start the game (1Accord 0): >"); scanf ("% d", & input); switch (input) {case 1: game (); break; case 0: printf ("Game out!") ; break; default: printf ("input error! please re-enter:"); break;}} while (input); return 0;}

Create the main function and menu, and judge the game selection.

two。 Design of the mineplate char mine [ROWS] [COLS]; / / minesweeping array char show [ROWS] [COLS]; / / display array InitMine (mine, ROWS, COLS,'0'); / / initialization of the mineplate InitShow (show, ROW, COL,'*'); / / initialization of the displayed mineplate

Here we create two two-dimensional arrays, the mine array is used to lay mines, and the show array is used to show the situation of the mineplate.

The InitMine function is implemented as follows:

Void InitMine (char mine [ROWS] [COLS], int row, int col) / / initialize the mineplate {int I = 0; int j = 0; for (I = 0; I < row; iTunes +) {for (j = 0; j < col; jacks +) {mine [I] [j] = '0mm;}

Next we need to show the lightning disk, but we will not show the mine that will be placed, so we use the show function to help us achieve this requirement.

The InitShow function is implemented as follows:

Void InitShow (char show [ROWS] [COLS], int row, int col,char set) / / initialize the displayed mineplate {int I = 0; int j = 0; for (I = 1; I)

Tags: Function number input array coordinates jackers statistics minesweeping legality minesweeping plus one selection menu error language success regret and then content actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Microsoft vpn NVidia Linux