当前位置:网站首页>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;}边栏推荐
- go语言(函数、闭包、defer、panic/recover,递归,结构体,json序列化与反序列化)
- SQL Server、MySQL主从搭建,EF Core读写分离代码实现
- 从面试官角度分析:面试功能测试工程师主要考察哪些能力?
- Install PyCharm on Raspberry Pi
- 一文解答web性能优化
- CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构
- HRNet-Facial-Landmark-Detection 训练自己数据集
- The Sandbox Partners with Gravity to Bring RO Ragnarok to the Metaverse
- 全国双非院校考研信息汇总整理 Part.2
- MySQL事务隔离级别详解
猜你喜欢

【openlayers】地图【一】

JetsonNano learning (5) JetsonNano installs PyTorch and Torchvision
![[leetcode] 82. Delete duplicate elements in sorted linked list II (medium)](/img/93/a744cfc059245de2fc07894167f3c5.png)
[leetcode] 82. Delete duplicate elements in sorted linked list II (medium)

Access Modbus TCP and Modbus RTU protocol devices using Neuron

Super RVRT
![CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构](/img/6a/0a446eb00fb73275897cbfb336e0b0.png)
CesiumJS 2022^ 源码解读[0] - 文章目录与源码工程结构

Redis系列:高可用之Sentinel(哨兵模式)

Hell Diggers Series #1

go语言(函数、闭包、defer、panic/recover,递归,结构体,json序列化与反序列化)

「大厂必备」系列之Redis主从、持久化、哨兵
随机推荐
对数据库进行增删改查操作
Wincc报表教程(SQL数据库的建立,wincc在数据库中保存和查询数据,调用Excel模板把数据保存到指定的位置和打印功能)
Codeforces Round #805 (Div. 3)总结
接口测试的概念、目的、流程、测试方法有哪些?
树莓派上安装 wiringPi 2.6 解决 gpio readall 命令的错误
C陷阱与缺陷 第4章 链接 4.3 命名冲突与static修饰符
资源集合
[2023 School Recruitment Questions] Summary of Common Interview Questions (7. Common Bus Protocols) (Continuously updated with subsequent interviews....)
Why does LabVIEW freeze when saving a VI
PyTorch笔记 - Attention Is All You Need (1)
Brute force recursion to dynamic programming 03 (knapsack problem)
【无标题】
y81. Chapter 4 Prometheus Factory Monitoring System and Actual Combat -- Monitoring Extension (12)
Elementary C language - first understanding of C language
关于MySQL索引的一些个人理解(部分参考MySQL45讲)
devops学习(八) 搭建镜像仓库---jenkins推送镜像
shell编写规范和变量
ApplicationContext的三大实现
种类并查集(反集),学习T宝代码
Prometheus 的功能特性