In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces the C language version of the minesweeper game how to achieve, the article introduces in great detail, has a certain reference value, interested friends must finish!
To do a simple implementation of the minesweeping function in C language, first create a test.c to test the minesweeping code on the way to write the code, game.h to store the header files needed to implement the minesweeping function, and game.c to store the final finished product.
First of all, use the function to print a menu that allows the player to choose to play the minesweeper or quit. Considering that the player will enter numbers other than 1 and 2, we add a fefault and put the menu into the do-while loop. The end condition of while is choose 0, and the player can go back to the cycle after the end of a game to ensure that the user can choose to continue to the next game or quit the game after the end of a minesweeper.
Void menu () {printf ("*\ n"); printf ("* * 1.playlists *\ n"); printf ("* * 0.quitters *\ n"); printf ("*\ n");} void test () {int choose; do {menu (); printf ("Please make your choice"); scanf ("% d", & choose) Switch (choose) {case 1: printf ("Game starts\ n"); break; case 2: printf ("Game exit\ n"); default: printf ("wrong choice, please reselect\ n");} while (choose);}
The game () function is added to case1 to implement the minesweeping game. Mine sweeping has mine layout and mine sweeping, first of all, to achieve mine layout, using a two-dimensional array to achieve a 9x9 chessboard, through the establishment of two chessboards to achieve information exchange, a chessboard hid mine layout, and a chessboard show to present the information to the players. Because the show chessboard needs to write out the number of eight grid mines that the user sweeps around the area, if you define an array of [9] [9], it will cross the line, so both arrays are positioned as 11x11, and macros define col=9 row=9 COL=col+2 ROW=row+2 for ease of writing. The initialization show array is all * and the hid array is all 0
Void SetBoard (char board [ROW] [COL], int rjingint c, char set) {for (int I = 0; I < r; iSense +) {for (int j = 0; j < c; jaun +) {board [I] [j] = set;}} void ShowBoard (char board [ROW] [COL], int rjint c) {for (int a = 0; a)
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.