当前位置:网站首页>C語言實現掃雷(簡易版)
C語言實現掃雷(簡易版)
2022-06-24 20:27: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;
}
边栏推荐
- Data backup and recovery of PgSQL
- Redis error: -bash: redis cli: command not found
- 顺序栈遍历二叉树
- Behind Tiantian Jianbao storm: tens of millions in arrears, APP shutdown, and the founder's premeditated plan to run away?
- VXLAN 与 MPLS:从数据中心到城域以太网
- Byte and Tencent have also come to an end. How fragrant is this business of "making 30million yuan a month"?
- Predicate
- The agile way? Is agile development really out of date?
- [cann document express issue 04] unveiling the development of shengteng cann operator
- Wait for the victory of the party! After mining ebb tide, graphics card prices plummeted across the board
猜你喜欢
Making startup U disk -- Chinese cabbage U disk startup disk making tool V5.1
Confirm whether the host is a large terminal or a small terminal
Using dynamic time warping (DTW) to solve the similarity measurement of time series and the similarity identification analysis of pollution concentration in upstream and downstream rivers
云计算发展的 4 个阶段,终于有人讲明白了
实现基于Socket自定义的redis简单客户端
Zadig + cave Iast: let safety dissolve in continuous delivery
Fundamentals of performance testing -- definitions of common terms
Teach you how to view the number of connected people on WiFi in detail how to view the number of connected people on WiFi
2022年最新四川建筑八大员(电气施工员)模拟题库及答案
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
随机推荐
两位湖南老乡,联手干出一个百亿IPO
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"
年轻人捧红的做饭生意经:博主忙卖课带货,机构月入百万
大一女生废话编程爆火!懂不懂编程的看完都拴Q了
Unit actual combat lol skill release range
With its own cells as raw materials, the first 3D printing ear transplantation was successful! More complex organs can be printed in the future
CVPR 2022缅怀孙剑!同济、阿里获最佳学生论文奖,何恺明入围
Redis installation of CentOS system under Linux, adding, querying, deleting, and querying all keys
【CANN文档速递04期】揭秘昇腾CANN算子开发
别再用 System.currentTimeMillis() 统计耗时了,太 Low,StopWatch 好用到爆!
Apache+php+mysql environment construction is super detailed!!!
Get to know the data structure of redis - hash
UART communication (STM32F103 library function)
苹果、微软、谷歌不再掐架,今年要合力干一件大事
[go language questions] go from 0 to entry 4: advanced usage of slice, elementary review and introduction to map
Dongyuhui is not enough to bring goods to "rescue" live broadcast
Win7 10 tips for installing Office2010 five solutions for installing MSXML components
Write a positive integer to the node and return a floating-point number multiplied by 0.85 when reading the node
Making startup U disk -- Chinese cabbage U disk startup disk making tool V5.1
Accurate calculation of task progress bar of lol mobile game