C语言实现简易扫雷

2021-04-02 06:26

阅读:472

标签:玩家   win   put   fine   crt   for   sign   while   语言   

game.h
#define _CRT_SECURE_NO_WARNINGS 1
#include 
#include 
#include 
#include 

#define ROW 9         //显示棋盘的大小
#define COL 9
#define ROWS ROW+2    //整个棋盘的大小
#define COLS COL+2

#define COUNT 10      //雷的数量

void chushihua(char arr[ROWS][COLS], int rows, int cols,char set);
void qipanxianshi(char arr[ROWS][COLS], int row, int col);
void buzhilie(char arr[ROWS][COLS], int row, int col);
void kaishipailei(char arr1[ROWS][COLS], char arr2[ROWS][COLS],int row, int col);

text.c

#include "game.h"

void saolie()
{
    char arr1[ROWS][COLS] = { 0 };
    char arr2[ROWS][COLS] = { 0 };
    //创建两个数组,一个放雷,一个显示
    chushihua(arr1, ROWS, COLS, ‘0‘);
    chushihua(arr2, ROWS, COLS, ‘*‘); //初始化两个棋盘
    qipanxianshi(arr2,ROW,COL); //打印一下棋盘
    buzhilie(arr1, ROW, COL);  //放置地雷
    qipanxianshi(arr1, ROW, COL); //测试打印一下带雷的棋盘
    kaishipailei(arr1,arr2,ROW,COL);
}

void meun()
{
    printf("================================\n");
    printf("=========== 1.开  始 ===========\n");
    printf("=========== 0.退  出 ===========\n");
    printf("================================\n");
}

void game()
{
    int input = 0;
    srand((unsigned int)time(NULL));
    do
    {       
        meun();
        printf("请选择:>");
        scanf("%d", &input);
        switch (input)
        {
        case 1:
            saolie();
            break;
        case 0:
            printf("游戏结束\n");
            break;
        default:
            printf("输入错误\n");
            break;
        }

    } while (input);
}

int main()
{
    game();
    return 0;
}

game.c


#include "game.h"

void chushihua(char arr[ROWS][COLS], int rows, int cols, char set)
{
    int i = 0;
    int j = 0;
    for ( i = 0; i ");
        scanf("%d%d", &num1, &num2);
        if (num1 >= 1 && num1 = 1 && num2 

C语言实现简易扫雷

标签:玩家   win   put   fine   crt   for   sign   while   语言   

原文地址:https://blog.51cto.com/14893161/2520622


评论


亲,登录后才可以留言!