求🐏了个🐏第二关的代码,c语言

主要是三维数组怎么写,如何实现明暗效果,如何让第二关有解

可以参考一下:
https://blog.csdn.net/qq_29887971/article/details/127714528
https://m.bilibili.com/video/BV1Kd4y1r7AM/


羊了个羊第二关代码 - 哔哩哔哩 点击进入查看全文> https://www.bilibili.com/read/cv18637136/

可以看看这个,简单点的,望采纳
https://blog.csdn.net/weixin_45713725/article/details/126910559?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-126910559-blog-126905160.pc_relevant_3mothn_strategy_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-126910559-blog-126905160.pc_relevant_3mothn_strategy_recovery&utm_relevant_index=9

如有帮助,望采纳

#include <stdio.h>
#include <graphics.h> //easyx
#include <time.h>
#include <mmsystem.h>

#define BLOCK_KINDS_1 3
#define WIN_W  504
#define WIN_H  900
#define BLOCK_W 61
#define BLOCK_H 68

//定义第一关的方格数
IMAGE imgBg; //用来表示背景图片
IMAGE imgBlocks[BLOCK_KINDS_1];
int map[3][3];
int chao[7] = { 0 };

struct location {
    int row;
    int col;
};


void initMap() {
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            map[i][j] = i + 1; // 1  2  3
        }
    }
    // 1  1   1
    // 2  2   2 
    // 3  3   3
    // 打乱
    srand(time(NULL)); //配置随机种子

    for (int i = 0; i < 20; i++) {
        int row1 = rand() % 3; //0,1,2
        int col1 = rand() % 3;
        int row2 = rand() % 3;
        int col2 = rand() % 3;

        int tmp = map[row1][col1];
        map[row1][col1] = map[row2][col2];
        map[row2][col2] = tmp;
    }
}
void gameInit() {
    // 加载游戏的资源
    // 背景图片
    loadimage(&imgBg, "res/bg.png");

    //小方块
    char fileName[256];
    for (int i = 0; i < BLOCK_KINDS_1; i++) {
        sprintf_s(fileName,
            sizeof(fileName),
            "res/%d.png", i + 1);
        loadimage(&imgBlocks[i], fileName);
    }

    // 初始化地图
    initMap();

    // 创建游戏的窗口
    initgraph(WIN_W, WIN_H, EW_SHOWCONSOLE);//控制台
}

bool userClick(struct location* loc) {
    ExMessage msg;
    if (peekmessage(&msg) && msg.message == WM_LBUTTONDOWN) {
        // 判断具体的位置
        int off = 10;
        int marginY = 270;
        int marginX = (WIN_W - BLOCK_W * 3 - off * 2) / 2;
        float x = (msg.x - marginX) * 1.0 / (BLOCK_W + off);
        // 0.0 - n.n
        // 0.09 最左边方块的左侧10%左右
        // 1.09
        // 0.99
        // 0
        int col = (x + 1) - 0.1;
        float tail = (x + 1) - 0.1 - col;  //得到小数部分
        if (col < 1 || col > 3 || tail > 0.6) {
            return false;
        }

        float y = (msg.y - marginY) * 1.0 / (BLOCK_H + off);
        float y2 = y + 1 - 0.1;
        int row = y2;
        tail = y2 - row;

        if (row < 1 || row > 3 || tail > 0.6) {
            return false;
        }

        loc->row = row;
        loc->col = col;

        printf("[%d,%d]", row, col);
        return true;
    }

    return false;
}


void update() {
    BeginBatchDraw();
    //先刷新背景图片,再去刷新其他部分
    // 问:怎样在游戏开发中,修改指定区域的图片
    // 答案:不需要修改,所有的游戏,都是全部重新渲染出来的,就是覆盖!
    putimage(0, 0,  //图片的左上角的坐标位置
        &imgBg);

    // 绘制游戏的中心区域的, 多个小方块
    /*
      1  1  1
        2  2  2
        3  3  3

        再随机打乱100次
    */

    // 第一关
    int off = 10;
    int marginX = (WIN_W - BLOCK_W * 3 - off * 2) / 2;
    int marginY = 270;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (map[i][j] == 0) continue;//如果为0则不渲染
            // 位置的计算
            int x = marginX + j * (BLOCK_W + off);
            int y = marginY + i * (BLOCK_H + off);
            // 到底画哪一个
            putimage(x, y, &imgBlocks[map[i][j] - 1]);
        }
    }

    marginX = 26;
    marginY = 691;
    for (int i = 0; i < 7; i++) {
        if (chao[i]) {
            int x = marginX + i * 64.7;
            int y = marginY + 5;
            putimage(x, y, &imgBlocks[chao[i] - 1]);
        }
    }


    EndBatchDraw();
}

//点击谁就把谁放在羊槽,下面第一一个数组。
//如果被点击数字,上面变成0则删掉,下面添加相应数字,然后渲染
void work(struct location* loc) {
    int index = map[loc->row - 1][loc->col - 1];
    map[loc->row - 1][loc->col - 1] = 0;

    // 放到羊槽的合适位置
    // 0 0 0 0 0 0 0 
    // 2 1 0 0 0 0 0
    //从左向右数,直到遇到第一个为0的位置
    int i = 0;
    for (; chao[i] && i < 7; i++);

    if (i < 7) {
        chao[i] = index;
    }

}


int main(void) {
    gameInit(); //游戏的初始化
    struct location loc; //表示玩家有效点击的位置
    while (1) {
        //刷新游戏窗口
        // 按键处理: 接口设计
        if (userClick(&loc)) {
            work(&loc);
        }
        update();
        //clear(&loc);
    }
    return 0;
}


可以考虑看看这些代码。

img