欢迎光临散文网 会员登陆 & 注册

谁能帮帮我看看这个c++《我的世界》简易版程序错哪里了?

2023-08-20 22:22 作者:克利莫夫斯基  | 我要投稿

代码如下,使用程序是GUIDE

#include <iostream>

#include<cstdio>

#include<cmath>


using namespace std;


// 定义方块的类型

enum BlockType {

    AIR, GRASS, DIRT, STONE, WATER, LAVA

};


// 定义方块对象

struct Block {

    BlockType type;


    Block(BlockType bType) {

        type = bType;

    }

};


// 定义玩家对象

struct Player {

    int x;

    int y;

    int z;


    Player() {

        x = y = z = 0;

    }

};


// 创建一个地图对象

 Block world[10][10][10];


// 初始化地图

void initWorld() {

    for (int i = 0; i < 10; i++) {

        for (int j = 0; j < 10; j++) {

            for (int k = 0; k < 10; k++) {

                if (i == 0 || i == 9 || j == 0 || j == 9 || k == 0 || k == 9) {

                    // 边界设置为石头方块

                    world[i][j][k] = Block(STONE);

                } else {

                    // 其他位置设置为空气方块

                    world[i][j][k] = Block(AIR);

                }

            }

        }

    }

}


// 在指定位置放置方块

void placeBlock(int x, int y, int z, BlockType type) {

    world[x][y][z] = Block(type);

}


// 打印当前玩家和周围方块信息

void printPlayerInfo(Player player) {

    cout << "玩家位置: (" << player.x << ", " << player.y << ", " << player.z << ")" << endl;

    cout << "玩家周围方块信息:" << endl;

    for (int i = -1; i <= 1; i++) {

        for (int j = -1; j <= 1; j++) {

            for (int k = -1; k <= 1; k++) {

                int x = player.x + i;

                int y = player.y + j;

                int z = player.z + k;


                if (x >= 0 && x < 10 && y >= 0 && y < 10 && z >= 0 && z < 10) {

                    BlockType type = world[x][y][z].type;

                    cout << "(" << x << ", " << y << ", " << z << "): " << type << endl;

                }

            }

        }

    }

}


int main() {

    Player player;


    // 初始化地图

    initWorld();


    // 打印玩家初始信息

    printPlayerInfo(player);


    // 在(1, 1, 1)处放置草地方块

    placeBlock(1, 1, 1, GRASS);


    // 移动玩家位置到(3, 3, 3)

    player.x = 3;

    player.y = 3;

    player.z = 3;


    // 打印移动后玩家信息

    printPlayerInfo(player);


    return 0;

}

错误显示:

MC.cpp:30: error: no matching function for call to `Block::Block()

翻译过来就是:MC.cpp:30:错误:调用Block::Block()没有匹配的函数(第三十行的block错误)

有谁懂的帮我看看呗


谁能帮帮我看看这个c++《我的世界》简易版程序错哪里了?的评论 (共 条)

分享到微博请遵守国家法律