当前位置:网站首页>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;}
边栏推荐
猜你喜欢
全网最强 JVM 来袭!(至尊典藏版)
MQTT over QUIC: The Next-Generation IoT Standard Protocol Brings New Impetus to Messaging Scenarios
JetsonNano learning (5) JetsonNano installs PyTorch and Torchvision
shell编写规范和变量
WLAN笔记
管理区解耦架构见过吗?能帮客户解决大难题的
2022年最新甘肃建筑施工焊工(建筑特种作业)模拟题库及答案解析
Foxmail是什么邮箱?
Wincc报表教程(SQL数据库的建立,wincc在数据库中保存和查询数据,调用Excel模板把数据保存到指定的位置和打印功能)
mysql使用on duplicate key update批量更新数据
随机推荐
devops学习(六)Jenkins 持续部署-版本选择
树莓派上安装 wiringPi 2.6 解决 gpio readall 命令的错误
[leetcode] The sword refers to Offer II 006. The sum of two numbers in a sorted array (binary search, double pointer)
Brute force recursion to dynamic programming 03 (knapsack problem)
Vulkan与OpenGL对比——Vulkan的全新渲染架构
Why does LabVIEW freeze when saving a VI
资源集合
Install PyCharm on Raspberry Pi
2022/7/29 考试总结
Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
Adaptive feature fusion pyramid network for multi-classes agriculturalpest detection
C语言初阶-初识C语言
暴力递归到动态规划 04 (数字字符串转化)
High - level - the rest - the client determine whether indexes exist
Sentinel入门
C陷阱与缺陷 第4章 链接 4.2 声明与定义
【openlayers】地图【二】
新标杆!美创科技助力广西桂林某三甲医院实现勒索病毒主动防御
环形链表(LeetCode 141、142)
Dropout回顾