简易版扫雷,看见有问题的麻烦评论一下,便于修改。。。。。





game2.h
#ifndef __GAME2__H__
#define __GAME2_H__
#define ROWS 9
#define LOCS 9
int init_arr(char arr[ROWS][LOCS], int row, int loc);
void dis_play(char arr[ROWS][LOCS], int row, int loc);
void Init_iay(char arr[ROWS][LOCS], int row, int loc);
int playgame(char arr1[ROWS][LOCS], char arr2[ROWS][LOCS], int no_count);
#endif
game.2c
#define _CRT_SECURE_NO_WARNINGS 1
#include"game2.h"
#include"string.h"
#include"stdlib.h"
#include"time.h"
#include"stdio.h"
int init_arr(char arr[ROWS][LOCS], int row, int loc)
{
	int  i, j,count=0,temp=0;
	
	for (i = 0; i < row; i++)
	{
		do
		{
			temp = 0;
			for (j = 0; j < loc; j++)
			{

				arr[i][j] = rand() % 5;
				if (arr[i][j]==3)
				{
					count++;
					temp++;
				}
			}
		} while (temp==0||temp==9);
	}
		
		
	
	return count;
}
void Init_iay(char arr[ROWS][LOCS], int row, int loc)
{
	memset(arr,'*' ,row*loc*sizeof(arr[0][0]));
}

void dis_play(char arr[ROWS][LOCS], int row, int loc)
{
	int i, j;
	for (i = 0; i < row; i++)
	{
		printf("  |%d", i + 1);
	}
	printf("\n");

	for (i = 0; i < row; i++)
	{
		printf("_____________________________________\n");
		printf("%d ", i+1);
		for (j = 0; j < loc; j++)
		{
			
			printf("| %c ", arr[i][j]);
		
		}
		printf("|\n");
		
	}
	printf("_____________________________________\n");

}
int playgame(char arr1[ROWS][LOCS], char arr2[ROWS][LOCS] ,int no_count)
{
	int x, y;
	printf("输入你选择的坐标》");
	scanf("%d%d", &x, &y);
	if (arr2[x-1][y-1] == ' ')
	{
		printf("已经选过此坐标,请重新选择坐标\n");
		scanf("%d%d", &x, &y);
	}
	if (arr1[x-1][y-1]== 3)
	{
		printf("踩中雷区\n\a");
		arr2[x - 1][y - 1] = '@';
		return 0;
	}
	else
	{
		arr2[x-1][y-1] = ' ';
		no_count=no_count-1;
	}
	if (no_count == 0)
		printf("玩家挑战成功");
	return no_count;
}
test.2
#define _CRT_SECURE_NO_WARNINGS 1
#include"stdio.h"
#include"game2.h"
#include"string.h"
#include"time.h"
#include"stdlib.h"

void play()
{
	int no_count,count;
	srand((unsigned int) time(NULL));
    char arr1[ROWS][LOCS] = { 0 };
	char arr2[ROWS][LOCS] = { 0 };
	count=init_arr(arr1, ROWS, LOCS);
	no_count = 81 - count;
		Init_iay(arr2, ROWS, LOCS);
		dis_play(arr2, ROWS, LOCS);
		do
		{
			no_count = playgame(arr1, arr2, no_count);
			dis_play(arr2, ROWS, LOCS);
		} while (no_count); 
}
mean()
{
	printf("**********************\n");
	printf("****play.1 exit.0*****\n");
	printf("**********************\n");
}
void test()
{
	int input;
	do
	{
		mean();
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			play();
			break;
		case 0:
			printf("游戏结束\n");
			break;
		default :
			printf("选择错误,请重新选择\n");
			break;


		}

	} while (input);
}

int main()
{
	test();
	system("pause");
	return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值