当前位置:网站首页>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;
}边栏推荐
- 16 excellent business process management tools
- 【CANN文档速递06期】初识TBE DSL算子开发
- Bytebase rejoint la communauté de base de données open source d'alicloud polardb
- 【Go語言刷題篇】Go從0到入門4:切片的高級用法、初級複習與Map入門學習
- You can capture fingerprints with a mobile camera?! Accuracy comparable to signature and monogram, expert: you are aggravating discrimination
- Byte and Tencent have also come to an end. How fragrant is this business of "making 30million yuan a month"?
- [R tidyverse] use of select verb
- Data backup and recovery of PgSQL
- Huawei cloud modelarts has ranked first in China's machine learning public cloud service market for the fourth time!
- Apache+php+mysql environment construction is super detailed!!!
猜你喜欢

What are the functions of IBPs open source form designer?

Bytebase加入阿里云PolarDB开源数据库社区

Data backup and recovery of PgSQL

The latest simulated question bank and answers of the eight members (Electrical constructors) of Sichuan architecture in 2022

Information theory of popular science Shannon

Based on STM32F103 0.96 inch OLED LCD driver (IIC communication)

Capacitive inching touch switch module control (stm32f103c8t6)

LCD1602 string display (STM32F103)

UART communication (STM32F103 library function)

Microsoft Office Excel 2013 2016 graphic tutorial on how to enable macro function
随机推荐
Redis error: -bash: redis cli: command not found
Material management system based on SSM (source code + document + database)
What about the Golden Angel of thunder one? Golden Angel mission details
Oracle create tablespaces and tables
Bytebase 加入阿里云 PolarDB 开源数据库社区
Otaku can't save yuan universe
苹果不差钱,但做内容“没底气”
unity实战之lol技能释放范围
lol手游之任务进度条精准计算
Capacitive inching touch switch module control (stm32f103c8t6)
unity之模糊背景(带你欣赏女人的朦胧美)
16个优秀业务流程管理工具
[go Language brossage] go from 0 to Getting started 4: Advanced use of slice, Primary Review and Map Getting started Learning
Bytebase rejoint la communauté de base de données open source d'alicloud polardb
思源笔记工具栏中的按钮名称变成了 undefined,有人遇到过吗?
Maps are grouped according to the values of the passed in parameters (similar to database groupby)
[cloud resident co creation] ModelBox draws your own painting across the air
视频平台如何将旧数据库导入到新数据库?
Steering gear control (stm32f103c8t6)
It is said that Tencent officially announced the establishment of "XR" department to bet on yuanuniverse; Former CEO of Google: the United States is about to lose the chip competition. We should let T