m0_59696689 2021-07-06 15:29 采纳率: 70.6%
浏览 57
已结题

求各位更改一下扫雷的基础代码,我这个运行一直出错

#include <stdio.h>
#include <stdlib.h>
#define VISIBLE_SAFE    0
#define HIDDEN_SAFE     1
#define HIDDEN_MINE     2

#define SIZE              8

void initialise_field(int minefield[SIZE][SIZE]);
void print_debug_minefield(int minefield[SIZE][SIZE],int number,int array_row[number],int array_column[number]);

int main(void) {
    int minefield[SIZE][SIZE];
    int number;
    initialise_field(minefield);
    int array_row[SIZE];
    int array_column[SIZE];
    printf("Welcome to minesweeper!\n");
    printf("How many mines? ");
    scanf("%d\n",&number);[

    int row,column;
    printf("Enter pairs:\n");
    int i = 0;
    while (number > i) {
        scanf("%d %d\n",&row,&column);
        array_row[i] = row;
        array_column[i] = column;
        i++;
    }
    printf("Game Started\n");
    print_debug_minefield(minefield,i,&array_row[i],&array_column[i]);


    // TODO: Scan in commands to play the game until the game ends.
    // A game ends when the player wins, loses, or enters EOF (Ctrl+D).
    // You should display the minefield after each command has been processed.


    return 0;
}

void initialise_field(int minefield[SIZE][SIZE]) {
    int i = 0;
    while (i < SIZE) {
        int j = 0;
        while (j < SIZE) {
            minefield[i][j] = HIDDEN_SAFE;
            j++;
        }
        i++;
    }
}

void print_debug_minefield(int minefield[SIZE][SIZE],int number,int array_row[number],int array_column[number]) {
    int i = 0;
    while (i < SIZE) {
        int j = 0;
        while (j < SIZE) {
            int a = 0;
            if (i == array_row[a] && j == array_column[a]) {
                while (a < number){
                    printf("%d ",HIDDEN_MINE);
                    a++;
                }
            } else {
                printf("%d ",minefield[i][j]);
            }
            j++;
        }
        printf("\n");
        i++;
    }
}

运行起来这样就行了。
img

  • 写回答

1条回答 默认 最新

  • 浪客 2021-07-06 17:25
    关注
    #include <stdio.h>
    #include <stdlib.h>
    
    #define VISIBLE_SAFE 0
    #define HIDDEN_SAFE 1
    #define HIDDEN_MINE 2
    #define SIZE 8
    
    typedef struct _point //雷的坐标
    {
        int x; //列
        int y; //行
    } Point;
    
    void init_field(int minefield[][SIZE], Point point[], int number) 
    {
        int i = 0;
        while (i < SIZE)
        {
            int j = 0;
            while (j < SIZE)
            {
                minefield[i][j] = HIDDEN_SAFE;
                j++;
            }
            i++;
        }
        //初始化的时候直接把雷得位置也写进去
        for (i = 0; i < number; i++)
        {
            if (point[i].y < SIZE && point[i].x < SIZE)
                minefield[point[i].y][point[i].x] = HIDDEN_MINE;
        }
    }
    
    //因为初始化的时候已经写入的雷的位置,直接输出就可以了。
    void print_minefield(int minefield[][SIZE])
    {
        int i = 0;
        while (i < SIZE)
        {
            int j = 0;
            while (j < SIZE)
            {
                printf("%d ", minefield[i][j]);
                j++;
            }
            i++;
            printf("\n");
        }
    }
    
    int main(void)
    {
        int minefield[SIZE][SIZE];
        int number;
        printf("Welcome to minesweeper!\n");
        printf("How many mines? ");
        scanf("%d", &number); //scanf("%d\n", &number);
    
        Point point[SIZE];
        printf("Enter pairs:\n");
        int i = 0;
        while (number > i)
        {
            scanf("%d%d", &point[i].y, &point[i].x); //scanf("%d %d\n", &row, &column);
            i++;
        }
    
        init_field(minefield, point, number);
    
        printf("Game Started\n");
        print_minefield(minefield);
    
        return 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 halcon DrawRegion 提示错误
  • ¥15 FastAPI Uvicorn启动显示404
  • ¥15 centos7.9脚本,怎么排除特定的访问记录
  • ¥15 关于#Django#的问题:我的静态文件呢?
  • ¥15 关于CPLEX的问题,请专家解答
  • ¥15 cocos的点击事件 怎么穿透到 原生fragment上。
  • ¥20 基于相关估计的TDOA算法中的加权最小二乘拟合法matlab仿真
  • ¥20 基于相关估计的TDOA算法中的自适应加权广义互相关法。
  • ¥15 abaqus CAE 2024软件启动问题
  • ¥20 基于相关估计的TDOA算法中的局部互相关函数滤波matlab仿真