#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;

// ========== 核心枚举定义(MC 1.8 全方块) ==========
enum BlockType {
    // 基础方块
    AIR, STONE, DIRT, GRASS, WOOD, COBBLESTONE, SAND, GRAVEL, GLASS,
    // 功能性方块
    CRAFTING_TABLE, FURNACE, ENCHANTING_TABLE, BREWING_STAND, CHEST, TRAPPED_CHEST, HOPPER, DISPENSER, DROPPER,
    // 红石方块
    REDSTONE_DUST, REDSTONE_TORCH, LEVER, STONE_BUTTON, WOODEN_BUTTON, PRESSURE_PLATE, PISTON, STICKY_PISTON, REDSTONE_REPEATER, REDSTONE_COMPARATOR,
    // 1.8 新增方块
    PRISMARINE_LAMP, PRISMARINE, WET_SPONGE, DRY_SPONGE, END_GATEWAY, BARRIER, STRUCTURE_BLOCK, CONDUIT_BLOCK,
    // 维度专属方块
    NETHER_QUARTZ_ORE, NETHER_WART_BLOCK, END_STONE, END_PORTAL_FRAME, OBSIDIAN, BEDROCK,
    // 特殊方块
    BED, CAKE, BEACON, ENCHANTED_BOOK_BLOCK, DRAGON_EGG, COMMAND_BLOCK,
    // 其他补充
    WATER, LAVA, TORCH, CHEST_MINECART, FURNACE_MINECART
};

// ========== 工具枚举(对应挖掘效率) ==========
enum ToolType {
    HAND, WOODEN_PICKAXE, STONE_PICKAXE, IRON_PICKAXE, GOLD_PICKAXE, DIAMOND_PICKAXE,
    WOODEN_AXE, STONE_AXE, IRON_AXE, GOLD_AXE, DIAMOND_AXE,
    WOODEN_SHOVEL, STONE_SHOVEL, IRON_SHOVEL, GOLD_SHOVEL, DIAMOND_SHOVEL
};

// ========== 玩家/世界状态定义 ==========
struct Player {
    // 基础属性
    int hp = 20;
    int hunger = 20;
    int exp = 0;
    int level = 0;
    // 位置
    int x = 10, y = 10, z = 10;
    // 维度(0=主世界,1=下界,2=末地)
    int dimension = 0;
    // 物品栏(工具+方块)
    map<ToolType, int> tools;
    map<BlockType, int> inventory;
    // 当前手持工具
    ToolType current_tool = HAND;
    // 红石信号状态(记录每个位置的红石信号强度)
    map<string, int> redstone_signal;
} player;

// ========== 世界地图(三维数组存储方块) ==========
BlockType world[50][50][50]; // X/Y/Z 范围 0-49

// ========== 方块属性配置(挖掘硬度、工具要求、特殊特性) ==========
struct BlockProperty {
    float hardness;       // 挖掘硬度(值越大越难挖)
    ToolType required_tool;// 挖掘所需工具(HAND=无要求)
    bool has_gravity;     // 是否有重力(沙子/砂砾)
    bool is_transparent;  // 是否透明(玻璃/空气)
    bool is_unbreakable;  // 是否不可破坏(基岩/屏障)
    bool is_water_block;  // 是否是水源方块
};

map<BlockType, BlockProperty> block_properties = {
    {AIR, {0.0f, HAND, false, true, false, false}},
    {STONE, {1.5f, WOODEN_PICKAXE, false, false, false, false}},
    {OBSIDIAN, {50.0f, DIAMOND_PICKAXE, false, false, false, false}},
    {BEDROCK, {0.0f, HAND, false, false, true, false}},
    {SAND, {0.5f, HAND, true, false, false, false}},
    {WET_SPONGE, {0.6f, HAND, false, false, false, true}},
    {DRY_SPONGE, {0.6f, HAND, false, false, false, false}},
    {END_PORTAL_FRAME, {100.0f, HAND, false, false, true, false}},
    {REDSTONE_REPEATER, {0.1f, HAND, false, false, false, false}},
    {PISTON, {0.5f, HAND, false, false, false, false}}
    // 可补充所有1.8方块的属性
};

// ========== 方块名称映射(用于输出) ==========
map<BlockType, string> block_names = {
    {AIR, "空气"}, {STONE, "石头"}, {DIRT, "泥土"}, {GRASS, "草方块"},
    {WET_SPONGE, "湿海绵"}, {DRY_SPONGE, "干海绵"}, {END_GATEWAY, "末地折跃门"},
    {OBSIDIAN, "黑曜石"}, {BEDROCK, "基岩"}, {REDSTONE_REPEATER, "红石中继器"},
    {PISTON, "活塞"}, {STICKY_PISTON, "粘性活塞"}, {WATER, "水"},
    {PRISMARINE_LAMP, "海晶灯"}, {COMMAND_BLOCK, "命令方块"}, {DRAGON_EGG, "龙蛋"}
    // 可补充所有1.8方块的名称
};

// ========== 核心函数:初始化世界 ==========
void init_world() {
    // 初始化所有方块为空气
    for (int x = 0; x < 50; x++) {
        for (int y = 0; y < 50; y++) {
            for (int z = 0; z < 50; z++) {
                world[x][y][z] = AIR;
            }
        }
    }
    // 生成基础地形(地面层)
    for (int x = 0; x < 50; x++) {
        for (int z = 0; z < 50; z++) {
            world[x][10][z] = GRASS;          // 表层草方块
            for (int y = 5; y < 10; y++) {
                world[x][y][z] = DIRT;        // 泥土层
            }
            for (int y = 0; y < 5; y++) {
                world[x][y][z] = STONE;       // 石头层
            }
        }
    }
    // 放置特殊方块(测试用)
    world[15][10][15] = WET_SPONGE;          // 湿海绵
    world[16][10][16] = OBSIDIAN;            // 黑曜石
    world[17][10][17] = REDSTONE_REPEATER;   // 红石中继器
    world[18][10][18] = PISTON;              // 活塞
    world[19][10][19] = END_PORTAL_FRAME;    // 末地传送门框架

    // 初始化玩家物品栏
    player.tools[IRON_PICKAXE] = 1;
    player.tools[DIAMOND_PICKAXE] = 1;
    player.current_tool = IRON_PICKAXE;
    player.inventory[STONE] = 64;
    player.inventory[DIRT] = 64;
}

// ========== 核心函数:挖掘方块(含1.8挖掘机制) ==========
void mine_block(int x, int y, int z) {
    BlockType target_block = world[x][y][z];
    if (target_block == AIR) {
        cout << "? 这里没有方块可挖掘!\n";
        return;
    }

    BlockProperty prop = block_properties[target_block];
    // 1. 检查是否不可破坏
    if (prop.is_unbreakable) {
        cout << "? " << block_names[target_block] << " 无法被破坏!\n";
        return;
    }

    // 2. 检查工具是否匹配
    bool can_mine = true;
    if (prop.required_tool != HAND && player.tools[prop.required_tool] == 0 && player.current_tool != prop.required_tool) {
        can_mine = false;
    }

    if (!can_mine) {
        cout << "? 需要 " << (prop.required_tool == DIAMOND_PICKAXE ? "钻石镐" : "木镐") << " 才能挖掘 " << block_names[target_block] << "!\n";
        return;
    }

    // 3. 计算挖掘时间(简化版,实际MC按硬度/工具效率计算)
    float mine_time = prop.hardness / (player.current_tool == DIAMOND_PICKAXE ? 12.0f : 4.0f);
    cout << "? 挖掘 " << block_names[target_block] << " 需要 " << mine_time << " 秒...\n";

    // 4. 挖掘成功,添加到物品栏
    world[x][y][z] = AIR;
    player.inventory[target_block]++;
    player.exp += (int)(prop.hardness * 5);
    player.level = player.exp / 100;
    cout << "? 成功挖掘 " << block_names[target_block] << "!经验+" << (int)(prop.hardness * 5) << ",等级=" << player.level << "\n";

    // 5. 处理重力方块(沙子/砂砾掉落)
    if (prop.has_gravity) {
        int fall_y = y + 1;
        while (fall_y < 49 && world[x][fall_y][z] == AIR) {
            fall_y++;
        }
        if (fall_y > y + 1) {
            world[x][fall_y - 1][z] = target_block;
            cout << "? " << block_names[target_block] << " 因重力掉落至 Y=" << fall_y - 1 << "!\n";
        }
    }
}

// ========== 核心函数:放置方块 ==========
void place_block(BlockType block, int x, int y, int z) {
    if (world[x][y][z] != AIR) {
        cout << "? 该位置已有 " << block_names[world[x][y][z]] << ",无法放置!\n";
        return;
    }
    if (player.inventory[block] <= 0) {
        cout << "? 物品栏中没有 " << block_names[block] << "!\n";
        return;
    }

    // 放置方块
    world[x][y][z] = block;
    player.inventory[block]--;
    cout << "? 成功放置 " << block_names[block] << " 到 (" << x << "," << y << "," << z << ")!\n";

    // 处理特殊方块的专属机制
    if (block == WET_SPONGE) {
        // 海绵吸水:清空周围3格内的水源
        int water_count = 0;
        for (int dx = -3; dx <= 3; dx++) {
            for (int dy = -3; dy <= 3; dy++) {
                for (int dz = -3; dz <= 3; dz++) {
                    int nx = x + dx, ny = y + dy, nz = z + dz;
                    if (nx >= 0 && nx < 50 && ny >= 0 && ny < 50 && nz >= 0 && nz < 50) {
                        if (world[nx][ny][nz] == WATER) {
                            world[nx][ny][nz] = AIR;
                            water_count++;
                        }
                    }
                }
            }
        }
        // 湿海绵变干海绵
        world[x][y][z] = DRY_SPONGE;
        player.inventory[WET_SPONGE]--;
        player.inventory[DRY_SPONGE]++;
        cout << "?? 湿海绵吸收了 " << water_count << " 格水源,变成干海绵!\n";
    } else if (block == END_GATEWAY) {
        // 末地折跃门传送机制
        if (player.dimension == 2) { // 仅末地可激活
            player.x = rand() % 50;
            player.z = rand() % 50;
            cout << "?? 末地折跃门激活!传送至 (" << player.x << "," << player.y << "," << player.z << ")!\n";
        } else {
            cout << "? 末地折跃门仅在末地可激活!\n";
        }
    } else if (block == REDSTONE_REPEATER) {
        // 红石中继器设置延迟(1-4刻,1刻=0.1秒)
        int delay = rand() % 4 + 1;
        string pos_key = to_string(x) + "," + to_string(y) + "," + to_string(z);
        player.redstone_signal[pos_key] = 15; // 红石信号强度15
        cout << "?? 放置红石中继器,延迟=" << delay << "刻,红石信号强度=15!\n";
    } else if (block == PISTON) {
        // 活塞推动前方方块
        int push_x = x + 1;
        if (push_x < 50 && world[push_x][y][z] != AIR && world[push_x][y][z] != BEDROCK) {
            BlockType pushed_block = world[push_x][y][z];
            world[push_x + 1][y][z] = pushed_block;
            world[push_x][y][z] = AIR;
            cout << "?? 活塞推动 " << block_names[pushed_block] << " 至 (" << push_x + 1 << "," << y << "," << z << ")!\n";
        } else {
            cout << "? 活塞前方无方块可推动!\n";
        }
    }
}

// ========== 核心函数:切换手持工具 ==========
void switch_tool(ToolType tool) {
    if (player.tools[tool] <= 0) {
        cout << "? 你没有该工具!\n";
        return;
    }
    player.current_tool = tool;
    string tool_name = (tool == DIAMOND_PICKAXE ? "钻石镐" : (tool == IRON_AXE ? "铁斧" : "手"));
    cout << "? 切换手持工具为:" << tool_name << "\n";
}

// ========== 指令帮助 ==========
void show_help() {
    cout << "\n===== MC 1.8 文字版指令大全 =====\n";
    cout << "1. 移动:move [x] [y] [z] (例:move 11 10 10)\n";
    cout << "2. 挖掘:mine [x] [y] [z] (例:mine 15 10 15)\n";
    cout << "3. 放置:place [方块名] [x] [y] [z] (例:place 湿海绵 20 10 20)\n";
    cout << "4. 切换工具:tool [工具名] (例:tool 钻石镐)\n";
    cout << "5. 状态:status (查看玩家状态)\n";
    cout << "6. 帮助:help (查看本指令)\n";
    cout << "7. 退出:exit (退出游戏)\n";
    cout << "==================================\n";
}

// ========== 玩家状态显示 ==========
void show_status() {
    cout << "\n===== 玩家状态 =====\n";
    cout << "生命值:" << player.hp << "/20\n";
    cout << "饥饿值:" << player.hunger << "/20\n";
    cout << "经验/等级:" << player.exp << "/" << player.level << "\n";
    cout << "当前位置:(" << player.x << "," << player.y << "," << player.z << ")\n";
    cout << "当前维度:" << (player.dimension == 0 ? "主世界" : (player.dimension == 1 ? "下界" : "末地")) << "\n";
    cout << "手持工具:" << (player.current_tool == DIAMOND_PICKAXE ? "钻石镐" : "铁镐") << "\n";
    cout << "当前位置方块:" << block_names[world[player.x][player.y][player.z]] << "\n";
    cout << "====================\n";
}

// ========== 主函数:指令交互 ==========
int main() {
    srand(time(0));
    init_world();
    cout << "===== 我的世界 1.8 文字版 =====\n";
    cout << "? 已加载全方块+全机制,输入 help 查看指令!\n\n";

    string cmd, param1, param2, param3, param4;
    while (true) {
        cout << "> ";
        cin >> cmd;

        if (cmd == "exit") {
            cout << "?? 游戏结束!\n";
            break;
        } else if (cmd == "help") {
            show_help();
        } else if (cmd == "status") {
            show_status();
        } else if (cmd == "move") {
            cin >> param1 >> param2 >> param3;
            int x = stoi(param1), y = stoi(param2), z = stoi(param3);
            if (x >= 0 && x < 50 && y >= 0 && y < 50 && z >= 0 && z < 50) {
                player.x = x;
                player.y = y;
                player.z = z;
                cout << "? 移动至 (" << x << "," << y << "," << z << ")!\n";
            } else {
                cout << "? 位置超出世界范围(0-49)!\n";
            }
        } else if (cmd == "mine") {
            cin >> param1 >> param2 >> param3;
            int x = stoi(param1), y = stoi(param2), z = stoi(param3);
            mine_block(x, y, z);
        } else if (cmd == "place") {
            cin >> param1 >> param2 >> param3 >> param4;
            int x = stoi(param2), y = stoi(param3), z = stoi(param4);
            // 简化版:匹配方块名(可扩展所有方块)
            BlockType block = AIR;
            if (param1 == "湿海绵") block = WET_SPONGE;
            else if (param1 == "黑曜石") block = OBSIDIAN;
            else if (param1 == "红石中继器") block = REDSTONE_REPEATER;
            else if (param1 == "活塞") block = PISTON;
            else if (param1 == "末地折跃门") block = END_GATEWAY;
            place_block(block, x, y, z);
        } else if (cmd == "tool") {
            cin >> param1;
            if (param1 == "钻石镐") switch_tool(DIAMOND_PICKAXE);
            else if (param1 == "铁镐") switch_tool(IRON_PICKAXE);
            else if (param1 == "手") switch_tool(HAND);
        } else {
            cout << "? 未知指令!输入 help 查看所有指令\n";
        }
    }
    return 0;
}

0 条评论

目前还没有评论...