#编写程序,实现扫雷游戏
程序代码如下:
game.h
#ifndef __GAME_H__
#define __GAME_H__
#define ROWS 11
#define COLS 11
#define ROW (ROWS-2)
#define COL (COLS-2)
#define COUNT 10
void InitBoard(char mine[ROWS][COLS], char show[ROWS][COLS], int rows, int cols);
void DisplayBoard(char show[ROWS][COLS], int row, int col);
void SetMine(char mine[ROWS][COLS], int count, int row, int col, int x, int y);
void GetMineCount(char mine[ROWS][COLS], char show[ROWS][COLS], int x, int y);
int UnknownNum(char show[ROWS][COLS], int row, int col);
#endif//__GAME_H__
game.c
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"
void InitBoard(char mine[ROWS][COLS], char show[ROWS][COLS],int rows, int cols)
{
memset(mine, '0', rows*cols*sizeof(mine[0][0]));
memset(show, '*', rows*cols*sizeof(show[0][0]));
}
void SetMine(char mine[ROWS][COLS], int count, int row, int col,int x,int y)
{
int i = 0;
while (count)
{
int X = rand() % row + 1 ;
int Y = rand() % col + 1;
if ((X != x) && (Y != y) && (mine[X][Y] == '0'))
{
m