Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Recursion to realize Demining Games in C language

2025-04-13 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces how to use recursion to achieve mine clearance games in C language, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.

Preface

Minesweeper, I believe you are no stranger. In the past, every computer would bring this Mini Game with it. Therefore, it can be said that our childhood memories, today to use C language to achieve a simple minesweeper Mini Game.

I. the idea of the game

1. A menu appears at the beginning of the program, allowing players to choose to start the game or quit the game.

2. After the player chooses to start the game, there will be a mineplate, and mines will be arranged randomly.

3. Players carry out demining

II. Game framework

1. Menu interface 1. Menu: void menu () {printf ("* *\ n"); printf ("* press 1 to start the game *\ n"); printf ("* press 0 to exit the game *\ n") Printf ("* *\ n");} 2. Menu choices: int main () {int input = 0; do {menu (); printf ("make your choice:"); scanf ("% d", & input); switch (input) {case 1: game () Break; case 0: printf ("quit the game ~)\ n"); break; default: printf ("Please reselect\ n"); break }} while (input); return 0;} 3. Actual effect:

two。 Game subject 1. Initialize the mineplate and display interface

Set up two two-dimensional arrays as mineplates, one for initializing the mineplate, that is, burying the mine, and the other for the display interface to show the player's demining process. The array size of the mineplate is 1111, which makes it easy to calculate the number of mines around the minesweeper and prevent the array from crossing the boundary. The array size of the display interface is 9 to 9.

Void game () {char mine [ROWS] [COLS] = {0}; / Information of mine placement char show [ROWS] [COLS] = {0}; / place information InitBoard of mine detection (mine, ROWS, COLS,'0'); / / initialize InitBoard (show, ROWS, COLS,'*'); / initialize display interface DisplayBoard (show, ROW, COL) / / print the display interface} void InitBoard (char board [ROWS] [COLS], int rows, int cols, char set) {int I = 0 rows; int j = 0 for (I = 0 for I < cols; I +) {for [j] = set;}} void DisplayBoard (char board [ROWS] [COLS], int row, int col) {int I = 0 int j = 0 for (I = 0bot I)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report