c语言实现简易版扫雷(源码)

我们需要建立三个文件:

一个test.c文件、一个game.c文件和一个game.h文件

内容如下:

game.h文件:

#define _CRT_SECURE_NO_WARNINGS 1
#pragma once
#define ROW 9    //显示的棋盘行数
#define COL 9    //显示的棋盘列数
#define ROWS ROW+2    //真实的棋盘行数
#define COLS COL+2    //真实的棋盘列数
#define COUNT 10  //雷的数目
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void InitBoard(char board[ROWS][COLS], char set);
void DisplayBoard(char board[ROWS][COLS]);
void SetMine(char board[ROWS][COLS]);
void FindMine(char mine[ROWS][COLS], char show[ROWS][COLS]);
unsigned Get_Mine_Count0(char mine[ROWS][COLS],char show[ROWS][COLS], int x, int y);
unsigned Get_Mine_Count1(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y);
unsigned Get_Mine_Count2(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y);
unsigned Get_Mine_Count3(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y);
unsigned Get_Mine_Count4(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y);
unsigned Get_Mine_Count5(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y);
unsigned Get_Mine_Count6(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y);
unsigned Get_Mine_Count7(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y);

test.c文件:

#include"game.h"
void menu()
{
	printf("         扫雷         \n");
	printf("1.开始游戏  0.退出游戏\n");
}
void game()
{
	//布置好的雷的信息
	char mine[ROWS][COLS] = { 0 };
	//排查出的雷的信息
	char show[ROWS][COLS] = { 0 };
	//棋盘初始化(11×11)
	InitBoard(mine,'0');
	InitBoard(show,'*');
	//打印棋盘(9×9)
	DisplayBoard(show);
	//布置雷(9×9)
	SetMine(mine);
	//DisplayBoard(mine); 展示布置出的雷
	//扫雷(9×9),需要同时操作两个数组
	FindMine(mine,show);
}
void test()
{
	srand((unsigned int)time(NULL));
	int answer;
	do 
	{
		menu();
		printf("请输入:");
		scanf("%d
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值