In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to achieve simple minesweeping function in C language". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "C language how to achieve simple minesweeping function"!
Let's look at the code:
Test.c
# define _ CRT_SECURE_NO_WARNINGS#include "game.h" void test (); void menu (); void game (); int main () {test (); return 0;} void menu () {printf ("*\ n"); printf ("* 1.play *\ n") Printf ("* 0.exit *\ n"); printf ("*\ n");} void test () {int input = 0; srand ((unsigned int) time (NULL)); do {menu (); printf ("Please choose:"); scanf ("% d", & input) Switch (input) {case 1: printf ("Minesweeper!\ n"); game (); break; case 0: printf ("quit the game!\ n"); break; default: printf ("input error, please re-enter!\ n"); break;}} while (input);} void game () {/ / mine information storage / / 1. Information about mine arrangement char mine [ROWS] [COLS] = {0}; / / 1111 / / 2. Char show [ROWS] [COLS] = {0}; / initialize InitBoard (mine, ROWS, COLS,'0'); InitBoard (show, ROWS, COLS,'*'); / / print chessboard DisplyBoard (mine, ROW, COL); / / DisplyBoard (show, ROW, COL); / / deploy SetMine (mine, ROW, COL); DisplyBoard (mine, ROW, COL); / / Minesweeper FindMine (mine, show, ROW, COL);}
Game.c
# define _ CRT_SECURE_NO_WARNINGS#include "game.h" / / '1'-'0'=1//'3'-'0'=3int get_mine_count (char mine [ROWS] [COLS], int x Int y) {return mine [x-1] [y-1] -'0' + mine [x] [y-1] -'0' + mine [x + 1] [y-1] -'0' + mine [x + 1] [y] -'0' + mine [x + 1] [y + 1] -'0' + mine [x] [y + 1] -'0' + mine [x-1] [y + 1]- '0' + mine [x-1] [y] -' 0' } void InitBoard (char board [ROWS] [COLS], int rows, int cols, char set) {int I = 0; int j = 0; for (I = 0; I < rows; iTunes +) {for (j = 0; j < cols; jacks +) {board [I] [j] = set;}} void DisplyBoard (char board [ROWS] [COLS], int row, int col) {int I = 0; int j = 0; / / print column number for (I = 0; 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.
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.