誰能幫幫我看看這個c++《我的世界》簡易版程序錯哪里了?
代碼如下,使用程序是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;
? ? }
};
// 創(chuàng)建一個地圖對象
?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) {
? ? ? ? ? ? ? ? ? ? // 邊界設(shè)置為石頭方塊
? ? ? ? ? ? ? ? ? ? world[i][j][k] = Block(STONE);
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? // 其他位置設(shè)置為空氣方塊
? ? ? ? ? ? ? ? ? ? world[i][j][k] = Block(AIR);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
// 在指定位置放置方塊
void placeBlock(int x, int y, int z, BlockType type) {
? ? world[x][y][z] = Block(type);
}
// 打印當(dāng)前玩家和周圍方塊信息
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:錯誤:調(diào)用Block::Block()沒有匹配的函數(shù)(第三十行的block錯誤)
有誰懂的幫我看看唄
