编辑代码

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void printArray(char arr[10][20]) {
    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 20;j++){
            printf("%c",arr[i][j]);
        }
        printf("\n");
    }
}

int main() {
    srand(time(0));
    char shuzu[10][20];
    int lei[10][20];
    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 20;j++){
            shuzu[i][j] = '#';
            lei[i][j] = 0;
            int suijishu = rand() % 100;
            if(suijishu < 99) {
                lei[i][j] = 1;
            }
        }
    }
    //int leix = 1 + rand() % 8;
    //int leiy = 1 + rand() % 18;
    //lei[leix][leiy] = 1;

    int x = 1;
    int y = 1;
    shuzu [x][y] = ' ';
    printArray(shuzu);
    system("stty -icanon");
    system("stty -echo");
    char ch = getchar();
    while (ch != 'q') {
        //shuzu[x][y] = '#';
        if (ch == 'w' && x > 1) {
                x--;
        } else if(ch == 'a' && y > 1) {
                y--;
        } else if(ch == 's' && x < 8) {
                x++;
        } else if(ch == 'd' && y < 18) {
               y++; 
        }
            shuzu[x][y] = ' ';
            system("clear");
            printArray(shuzu);
            if(lei[x][y] == 1){
                printf("Game Over!\n");
                break;
            }
            ch = getchar();
    }
    return 0;
}