当前位置:网站首页>C语言实现扫雷(简易版)
C语言实现扫雷(简易版)
2022-06-24 19:03:00 【AKA.瞳源治】
#define ROW 9
#define COL 9
#define ROWS 2 + ROW
#define COLS 2 + COL
#define shuliang 10
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<time.h>
#include<Windows.h>
void quyu(char mine[ROWS][COLS], int rows, int cols, char n)
{
int i = 0;
int j = 0;
for (i = 0; i < rows; i++)
{
for (j = 0; j < cols; j++)
{
mine[i][j] = n;
}
}
}
void xianshi(char show[ROWS][COLS], int row, int col)
{
int i = 0;
int j = 0;
for (i = 0; i <= col; i++)
{
printf("%d ", i);
}
printf("\n");
for (i = 1; i <= row; i++)
{
printf("%d ", i);
for (j = 1; j <= col; j++)
{
printf("%c ", show[i][j]);
}
printf("\n");
}
printf("\n");
}
void buzhi(char mine[ROWS][COLS], int row, int col)
{
int m = shuliang;
int x = 0;
int y = 0;
while (m)
{
x = rand() % row + 1;
y = rand() % row + 1;
if (mine[x][y] == '0')
{
mine[x][y] = '1';
m--;
}
}
}
int zhouweilei(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 play(char mine[ROWS][COLS], char show[ROWS][COLS], int row, int col)
{
int x = 0;
int y = 0;
int win = 0;
while (win < row * col - shuliang)
{
printf("请输入坐标:");
scanf("%d %d", &x, &y);
if (x >= 1 && x <= row && y >= 1 && y <= col)
{
if (mine[x][y] == '1')
{
printf("死\n");
xianshi(mine, ROW, COL);
printf("游戏结束\n");
break;
}
else
{
int m = zhouweilei(mine, x, y);
show[x][y] = m + '0';
xianshi(show, ROW, COL);
}
}
else
{
printf("请重新输入\n");
continue;
}
win++;
}
if (win == row * col - shuliang)
{
printf("赢了\n");
xianshi(mine, ROW, COL);
}
}
void meun()
{
Sleep(5000);
char a1[] = "******** 1. play *******";
char a2[] = "******** 0. exit *******";
char a3[] = "######## #######";
char a4[] = "######## #######";
int left1 = 0;
int right1 = strlen(a1) - 1;
int left2 = 0;
int right2 = strlen(a2) - 1;
while (left1 < right1 && left2 < right2)
{
a3[left1] = a1[left1];
a3[right1] = a1[right1];
a4[left2] = a2[left2];
a4[right2] = a2[right2];
printf("%s\n", a3);
printf("%s\n", a4);
left1++;
right1--;
left2++;
right2--;
Sleep(100);
system("cls");
}
printf("%s\n", a3);
printf("%s\n", a4);
}
void game()
{
char mine[ROWS][COLS] = { 0 };
char show[ROWS][COLS] = { 0 };
quyu(mine, ROWS, COLS, '0');
quyu(show, ROWS, COLS, '*');
buzhi(mine, ROW, COL);
xianshi(show, ROW, COL);
play(mine, show, ROW, COL);
}
void saolei()
{
int xuanze = 0;
srand((unsigned int)time(NULL));
do
{
meun();
printf("请输入:");
scanf("%d", &xuanze);
switch (xuanze)
{
case 1:
printf("开始游戏\n");
game();
break;
case 0:
printf("退出游戏\n");
break;
default:
printf("输入错误\n");
break;
}
} while (xuanze);
}
int main()
{
saolei();
return 0;
}边栏推荐
- Saltstack state state file configuration instance
- Apple, Microsoft and Google will no longer fight each other. They will work together to do a big thing this year
- Bytebase joins Alibaba cloud polardb open source database community
- [go Language brossage] go from 0 to Getting started 4: Advanced use of slice, Primary Review and Map Getting started Learning
- [cann document express issue 05] let you know what operators are
- Database index can improve query efficiency. Ask what will improve, what is the difference between inapplicable index and index use, and what will happen.
- Behind Tiantian Jianbao storm: tens of millions in arrears, APP shutdown, and the founder's premeditated plan to run away?
- Redis installation of CentOS system under Linux, adding, querying, deleting, and querying all keys
- Comparative analysis of arrayblockingqueue and linkedblockingqueue
- Five day summary of software testing
猜你喜欢

JMeter environment deployment
![[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map](/img/3a/db240deb4c66b219ef86f40d4c7b7d.png)
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map

Behind Tiantian Jianbao storm: tens of millions in arrears, APP shutdown, and the founder's premeditated plan to run away?

Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial

Kubernetes cluster deployment

Obstacle avoidance sensor module (stm32f103c8t6)

2022年最新四川建筑八大员(电气施工员)模拟题库及答案

The Network Security Review Office launched a network security review on HowNet, saying that it "has a large amount of important data and sensitive information"

实现基于Socket自定义的redis简单客户端

16 excellent business process management tools
随机推荐
思源笔记工具栏中的按钮名称变成了 undefined,有人遇到过吗?
2022年最新四川建筑八大员(电气施工员)模拟题库及答案
Two solutions to the problem of 0xv0000225 unable to start the computer
用自身细胞作为原料,首例3D打印耳朵移植成功!未来可打印更复杂器官
苹果、微软、谷歌不再掐架,今年要合力干一件大事
Clustered index (clustered index), nonclustered index (nonclustered index)
天天鉴宝暴雷背后:拖欠数千万、APP停摆,创始人预谋跑路?
[go Language brossage] go from 0 to Getting started 4: Advanced use of slice, Primary Review and Map Getting started Learning
Coinbase will launch the first encryption derivative for individual investors
Bytebase rejoint la communauté de base de données open source d'alicloud polardb
华为云ModelArts第四次蝉联中国机器学习公有云服务市场第一!
Wait for the victory of the party! After mining ebb tide, graphics card prices plummeted across the board
Data backup and recovery of PgSQL
The difference between the lazy man mode and the hungry man mode
Obstacle avoidance sensor module (stm32f103c8t6)
Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial
First understand redis' data structure - string
Todesk remote control, detailed introduction and tutorial
Hutool reads large excel (over 10m) files
SQL export CSV data, unlimited number of entries