要怎么实现可以用鼠标进行实时修改二维数组的字符,而不是需要用键盘输入坐标进行修改#include <stdio.h>

要怎么实现可以用鼠标进行实时修改二维数组的字符,而不是需要用键盘输入坐标进行修改

#include 
#include 
#define ROW 11                 //游戏区行数
#define COL 11                 //游戏区列数     

char map[ROW][COL] = {
    {'F', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},   //x为草坪
    {'t', '~', '~', '~', '~', '~', '~', '~', '~', '~'},   //~为水流
    {'t', 't', '~', '~', 't', '~', 't', 't', '~', '~'},   //o为终点
    {'t', '~', 't', 't', '~', '~', '~', '~', '~', '~'},      //t为乌龟
    {'~', 't', '~', '~', '~', '~', 't', '~', '~', '~'},
    {'~', '~', '~', '~', 't', '~', '~', '~', '~', 't'},
    {'t', '~', '~', '~', '~', '~', 't', '~', '~', '~'},
    {'~', 't', 't', 't', '~', 't', '~', '~', 't', '~'},
    {'~', '~', 't', '~', '~', '~', '~', 't', '~', '~'},
    {'~', '~', '~', '~', '~', '~', '~', '~', '~', '~'},
    {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'o', 'x'}
};


int main() {

    int i, j;
    int n = 1;
    int x = 0, y = 0;
    char c;
    while (1) {
        n = 1;
        printf("输入wsad控制青蛙的移动\n");
        printf("输入l添加浮木的位置\n");
        printf("输入k清除浮木需要删除的位置\n");
        printf("输入b添加臭虫的位置\n");
        printf("0   1   2   3   4   5   6   7   8   9   10\n");
        for (i = 0; i < ROW; i++) {
            if (n <= 9)
                printf("%d ", n);
            else
                printf("%d", n);
            n++;
            for (j = 0; j < COL; j++) {
                printf("  %c ", map[i][j]);     //生成游戏界面
            }
            printf("\n");
        }
        printf("请输入操作:\n");
        scanf("%c", &c);                     //w s a d
        getchar();                           //防止重复出现的二维数组
        system("cls");                      //清理屏幕
        static char q = 'x';
        if (c == 'w') {

            map[x][y] = q;
            q = map[x - 1][y];
            map[x - 1][y] = 'F';
            x = x - 1;

        }

        else if (c == 's') {
            map[x][y] = q;
            q = map[x + 1][y];
            map[x + 1][y] = 'F';

            x = x + 1;

        }

        else if (c == 'a') {
            map[x][y] = q;
            q = map[x][y - 1];
            map[x][y - 1] = 'F';

            y = y - 1;

        }

        else if (c == 'd') {
            map[x][y] = q;
            q = map[x][y + 1];
            map[x][y + 1] = 'F';

            y = y + 1;

        }

        else if (c == 'l') {
            int a, b;
            printf("添加浮木:请输入浮木放置的横坐标和纵坐标\n");//添加浮木
            scanf("%d%d", &a, &b);
            getchar();
            map[b - 1][a - 1] = 'L';

        }

        else if (c == 'k') {
            int a, b;
            printf("清除浮木:请输入需要清除浮木的横坐标和纵坐标\n");//清除浮木
            scanf("%d%d", &a, &b);
            getchar();
            if (map[b - 1][a - 1] == 'L') {
                map[b - 1][a - 1] = '~';
            } else if (map[b - 1][a - 1] == '~' || map[b - 1][a - 1] == 'F' || map[b - 1][a - 1] == 't' || map[b - 1][a - 1] == 'x'
                       || map[b - 1][a - 1] == 'B') {
                printf("该位置没有浮木");
            }
        }



        else if (c == 'b') {
            int a, b;
            printf("请输入臭虫放置的横坐标和纵坐标\n");           //添加臭虫
            scanf("%d%d", &a, &b);
            getchar();
            if (map[b - 1][a - 1] == 'L') {
                map[b - 1][a - 1] = 'B';
            } else if (map[b - 1][a - 1] == '~' || map[b - 1][a - 1] == 'F' || map[b - 1][a - 1] == 't' || map[b - 1][a - 1] == 'x')
                printf("臭虫没有放在浮木上\n");
        }
        if ( q == '~' || q == 'B') {
            printf("game over\n");
            break;
        } else if (q == 'o') {
            printf("Congratulations on winning\n");
            break;
        }

    }
    return 0;
}

#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>

#define ROW 11
#define COL 11

char map[ROW][COL] = {
    {'F', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x'},
    {'t', '~', '~', '~', '~', '~', '~', '~', '~', '~'},
    {'t', 't', '~', '~', 't', '~', 't', 't', '~', '~'},
    {'t', '~', 't', 't', '~', '~', '~', '~', '~', '~'},
    {'~', 't', '~', '~', '~', '~', 't', '~', '~', '~'},
    {'~', '~', '~', '~', 't', '~', '~', '~', '~', 't'},
    {'t', '~', '~', '~', '~', '~', 't', '~', '~', '~'},
    {'~', 't', 't', 't', '~', 't', '~', '~', 't', '~'},
    {'~', '~', 't', '~', '~', '~', '~', 't', '~', '~'},
    {'~', '~', '~', '~', '~', '~', '~', '~', '~', '~'},
    {'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'o', 'x'}};

static void draw_cb(GtkWidget *widget, cairo_t *cr, gpointer data)
{
    for (int i = 0; i < ROW; i++)
    {
        for (int j = 0; j < COL; j++)
        {
            char c = map[i][j];
            double x = j * 50;
            double y = i * 50;
            if (c == 'x')
                cairo_set_source_rgb(cr, 0.5, 0.5, 0.5);
            else if (c == 't')
                cairo_set_source_rgb(cr, 0, 0, 1);
            else if (c == '~')
                cairo_set_source_rgb(cr, 0, 0, 1);
            else if (c == 'o')
                cairo_set_source_rgb(cr, 1, 0, 0);
            else
                cairo_set_source_rgb(cr, 0, 0, 0);
            cairo_rectangle(cr, x, y, 50, 50);
            cairo_fill(cr);
        }
    }
}

static gboolean button_press_event_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
    int x = event->x / 50;
    int y = event->y / 50;
    printf("Clicked at (%d, %d)\n", x, y);
    if (event->button == GDK_BUTTON_PRIMARY)
        map[y][x] = 't';
    else if (event->button == GDK_BUTTON_SECONDARY)
        map[y][x] = '~';
    gtk_widget_queue_draw(widget);
    return TRUE;
}

int main(int argc, char *argv[])
{
    gtk_init(&argc, &argv);
    GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Frogger");
    gtk_window_set_default_size(GTK_WINDOW(window), COL * 50, ROW * 50);
    GtkWidget *drawing_area = gtk_drawing_area_new();
    gtk_container_add(GTK_CONTAINER(window), drawing_area);
    g_signal_connect(G_OBJECT(drawing_area), "draw", G_CALLBACK(draw_cb), NULL);
    g_signal_connect(G_OBJECT(drawing_area), "button-press-event", G_CALLBACK(button_press_event_cb), NULL);
    g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
    gtk_widget_show_all(window);
    gtk_main();
    return 0;
}

仅供参考,望采纳。