当前位置:网站首页>Minesweeper game in c language
Minesweeper game in c language
2022-07-29 23:51:00 【so-and-so Xiaolu】
C language game Minesweeper
Header file
#pragma once#define ROW 9#define COL 9#define ROWS ROW+2#define COLS COL+2#define easy_count 10#include#include#includevoid start__board(char board[ROWS][COLS], int rows, int cols, char rew);void start__qipan(char board[ROWS][COLS], int row, int col);void start__mine(char mine[ROWS][COLS], int row, int col);void find__mine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col); A source file that implements each small function
#include "game.h"void start__board(char board[ROWS][COLS], int rows, int cols, char rew){int i = 0;int j = 0;for (int i = 0; i <= rows; i++){for (int j = 0; j <= cols; j++){board[i][j] = rew;}}}void start__qipan(char board[ROWS][COLS], int row, int col){int i = 0;int j = 0;for (int i = 0; i <= row; i++){printf("%d ", i);}printf("\n");for (int i = 1; i <= row; i++){printf("%d ", i);for (int j = 1; j <= col; j++){printf("%c ", board[i][j]);}printf("\n");}printf("\n");}void start__mine(char mine[ROWS][COLS], int row, int col){int count = 10;while (count){int x = rand() % row + 1;int y = rand() % col + 1;if (mine[x][y] == '0'){mine[x][y] = '1';count--;}}}int count__mine(char mine[ROWS][COLS], int x, int y){return (mine[x - 1][y - 1] +mine[x - 1][y] +mine[x - 1][y + 1] +mine[x][y - 1] +mine[x][y + 1] +mine[x + 1][y - 1] +mine[x + 1][y] +mine[x + 1][y + 1] - 8 * '0');}void find__mine(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col){int sum = 0;int x, y;int win = 0;while (win < row * col - easy_count){printf("Please enter the coordinates to clear mine:->");scanf_s("%d %d", &x, &y);if (x >= 1 && x <= row && y >= 1 && y <= col){if (show[x][y] == '*'){if (mine[x][y] == '1'){printf("Sorry, you were killed\n");start__qipan(mine, ROW, COL);break;}else{int sum = count__mine(mine, x, y);show[x][y] = sum + '0';start__qipan(show, ROW, COL);win++;}}else{printf("The coordinates have been checked");}}else{printf("Illegal coordinates, please re-enter");}if (win = row * col - easy_count){printf("Congratulations on your successful demining\n");start__qipan(mine, ROW, COL);}}}Main function file
#include "game.h"void menu(){printf("****************************\n");printf("********* 1.play ********\n");printf("************ 0.exit ********\n");printf("****************************\n");}void game(){char mine[ROWS][COLS];char show[ROWS][COLS];start__board(mine,ROWS,COLS,'0');start__board(show, ROW, COL, '*');//start__qipan(mine, ROW, COL);//start__qipan(show, ROW, COL);start__mine(mine, ROW, COL);start__qipan(show, ROW, COL);find__mine(mine, show, ROW, COL);}int main(){srand((unsigned int)time(NULL));int m;do{menu();printf("Please select:->\n");scanf_s("%d", &m);switch (m){case 1:game();break;case 0:printf("Exit the game\n");break;default:printf("Incorrect selection, please re-select:\n");break;}} while (m);return 0;}边栏推荐
猜你喜欢
随机推荐
运动步数抽奖小程序开发
微信小程序获取手机号getPhoneNumber接口报错41001
仿牛客论坛项目部署总结
The latest Gansu construction welder (construction special operation) simulation question bank and answer analysis in 2022
SQL Server、MySQL主从搭建,EF Core读写分离代码实现
一文解答web性能优化
资源集合
jenkins搭建部署详细步骤
Sentinel入门
[leetcode] 75. Color classification (medium) (double pointer, in-situ modification)
leetcode122. Best Time to Buy and Sell Stock II 买卖股票的最佳时机 II(简单)
MQTT over QUIC: The Next-Generation IoT Standard Protocol Brings New Impetus to Messaging Scenarios
MySQL【基本select语句】
devops学习(三) K8环境部署jenkins
Qt uses QSortFilterProxyModel for sorting and filtering in QML
桌面软件开发框架大赏
r‘w‘r‘w‘r‘w‘r
全网最强 JVM 来袭!(至尊典藏版)
Framework 到底该怎么学习?
Override and customize dependent native Bean methods



![[leetcode] 75. Color classification (medium) (double pointer, in-situ modification)](/img/0e/e4ed76902194755a3b075a73f272f3.png)





