求大佬帮忙看一下有什么问题

该代码示例展示了一个使用C++进行图形游戏编程的小程序,包括定义了结构体POS来存储位置信息,使用enum_PROPS枚举类型表示游戏元素,以及处理用户输入和地图变化的函数。程序加载不同图像资源并显示在屏幕上,玩家可以通过键盘控制角色移动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <graphics.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>
using namespace std;


#define SCRENEN_WIDTH 800
#define SCREENN_HEIGHT 650
#define LINE 9
#define LIE 12
#define FIFTY 50
#define START_L 100
#define START_C 100
#define PANDUAN(next_pos) (next_pos.line >= 0 && next_pos.line < LINE && next_pos.coll >= 0 && next_pos.coll < LIE)

typedef struct _POS {
    int line;
    int coll;
}POS;

enum _PROPS {
    WALL,
    FLOOR,
    DES,
    MAN,
    BOX,
    ALL,
};

IMAGE images[ALL];
POS man;

int maps[LINE][LIE] = {
    {0,0,0,0,0,0,0,0,0,0,0,0},
    {0,1,0,1,1,1,1,1,1,1,0,0},
    {0,1,4,1,0,2,1,0,2,1,0,0},
    {0,1,0,1,0,1,0,0,1,1,1,0},
    {0,1,0,2,0,1,1,4,1,1,1,0},
    {0,1,1,1,0,3,1,1,1,4,1,0},
    {0,1,2,1,1,4,1,1,1,1,1,0},
    {0,1,0,0,1,0,1,1,0,0,1,0},
    {0,0,0,0,0,0,0,0,0,0,0,0},
};

void changemap(POS* pos, enum _PROPS prop)
{
    maps[pos->line][pos->coll] = prop;
    putimage(START_C + pos->coll * FIFTY, START_L + pos->line * FIFTY, &images[prop]);
}
void Gc(char dr)
{
    POS next_pos;
    POS next_next_pos;

    switch (dr)
    {
    case 'w':
        next_pos.line = man.line - 1;
        next_next_pos.line = next_pos.line - 1;
        break;
    case's':
        next_pos.line = man.line + 1;
        next_next_pos.line = next_pos.line + 1;
        break;
    case'a':
        next_pos.coll = man.coll - 1;
        next_next_pos.coll = next_pos.coll - 1;
        break;
    case'd':
        next_pos.coll = man.coll + 1;
        next_next_pos.coll = next_pos.coll + 1;
        break;
    default:
        return;
    }

    if (PANDUAN(next_pos) && maps[next_pos.line][next_pos.coll] == FLOOR)
    {
        changemap(&next_pos, MAN);
        changemap(&man, FLOOR);
        man = next_pos;
    }
}

int main(void)
{
    IMAGE ISACI;
    initgraph(SCRENEN_WIDTH, SCREENN_HEIGHT);
    loadimage(&ISACI, "blackground.bmp", SCRENEN_WIDTH, SCRENEN_WIDTH, true);
    putimage(0, 0, &ISACI);

    loadimage(&images[WALL], "wall_right.bmp", FIFTY, FIFTY, true);
    loadimage(&images[FLOOR], "floor.bmp", FIFTY, FIFTY, true);
    loadimage(&images[DES], "des.bmp", FIFTY, FIFTY, true);
    loadimage(&images[MAN], "man.bmp", FIFTY, FIFTY, true);
    loadimage(&images[BOX], "box.bmp", FIFTY, FIFTY, true);


    for (int i = 0; i < LINE; i++)
    {
        for (int j = 0; j < LIE; j++)
        {
            if (maps[i][j] == MAN)
            {
                man.line = i;
                man.coll = j;
            }
            putimage(START_C + j * FIFTY, START_L + i * FIFTY, &images[maps[i][j]]);
        }
    }

    bool quit = false;

    do {
        if (_kbhit())
        {
            char key = _getch();
            if (key == 'w')
                Gc('w');
            else if (key == 's')
                Gc('s');
            else if (key == 'a')
                Gc('a');
            else if (key == 'd')
                Gc('d');
            else if (key == 'q')
                quit = true;
        }

    } while (!quit);
    system("pause");
    return 0;
}
Run-Time Check Failure #3 - The variable 'next_pos' is being used without being initialized.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值