问题标题: MC

0
0
已解决
陶朴鸣
陶朴鸣
修练者
修练者

#include <iostream>
#include <conio.h>
#include <windows.h>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

// 地图尺寸
const int WIDTH = 40;
const int HEIGHT = 22;

// 方块ID
enum Block {
    AIR, DIRT, STONE, WOOD, LEAF, COAL, IRON, GOLD, DIAMOND,
    TORCH, BED, CRAFT_TABLE, ENCHANT_TABLE, REDSTONE, REDSTONE_LAMP,
    LEVER, NETHER_PORTAL, FURNACE, SMITHING_TABLE
};

// 实体类型
enum EntityType { PLAYER, ZOMBIE, SKELETON, SHEEP, PIG, CHICKEN, VILLAGER };

// 实体结构体
struct Entity {
    int x, y;
    EntityType type;
    int hp;
};

// 玩家全局数据
int map[HEIGHT][WIDTH] = { 0 };
int playerX = WIDTH / 2, playerY = 10;
int hp = 20, **ger = 20, exp = 0, level = 1;
int inv[30] = { 0 };

// 装备 & 锻造
bool hasSword = false, hasBow = false;
int swordEnchant = 0;
int pickEnchant = 0;
int toolDurability = 100;
bool hasIronSword = false;
bool hasDiamondSword = false;
bool hasAlloySword = false;

// 游戏状态
bool isNight = false;
bool isRain = false;
bool flyMode = false;
int timeTick = 0;

// 实体列表
vector<Entity> entities;

// 清屏
void clear() { system("cls"); }

// 随机地形生成
void generateTerrain() {
    for (int x = 0; x < WIDTH; x++) {
        int h = 11 + rand() % 4;
        for (int y = h; y < HEIGHT; y++) map[y][x] = DIRT;
        for (int y = h - 3; y < h; y++) map[y][x] = STONE;
    }
    
    // 生成树木
    for (int i = 0; i < 12; i++) {
        int x = rand() % WIDTH;
        map[8][x] = WOOD; map[7][x] = WOOD;
        map[6][x-1] = LEAF; map[6][x] = LEAF; map[6][x+1] = LEAF;
        map[5][x] = LEAF;
    }
    
    // 生成矿物
    for (int x = 0; x < WIDTH; x++) {
        for (int y = 0; y < 11; y++) {
            if (map[y][x] == STONE) {
                int r = rand() % 100;
                if (r < 4) map[y][x] = COAL;
                else if (r < 7) map[y][x] = IRON;
                else if (r < 9) map[y][x] = GOLD;
                else if (r < 11) map[y][x] = DIAMOND;
                else if (r < 14) map[y][x] = REDSTONE;
            }
        }
    }
    
    // 固定生成功能**方块
    map[10][5]  = ENCHANT_TABLE;
    map[10][30] = NETHER_PORTAL;
    map[12][15] = LEVER;
    map[12][18] = REDSTONE_LAMP;
    map[13][8]  = FURNACE;
    map[13][12] = SMITHING_TABLE;
}

// 绘制方块字符
void drawBlock(int b) {
    switch (b) {
        case AIR:        cout << "  "; break;
        case DIRT:       cout << "土"; break;
        case STONE:      cout << "石"; break;
        case WOOD:       cout << "木"; break;
        case LEAF:       cout << "叶"; break;
        case COAL:       cout << "煤"; break;
        case IRON:       cout << "铁"; break;
        case GOLD:       cout << "金"; break;
        case DIAMOND:    cout << "钻"; break;
        case TORCH:      cout << "火"; break;
        case BED:        cout << "床"; break;
        case CRAFT_TABLE:cout << "台"; break;
        case ENCHANT_TABLE:cout << "魔"; break;
        case REDSTONE:   cout << "红"; break;
        case REDSTONE_LAMP:cout << (isRain?"亮":"暗"); break;
        case LEVER:      cout << "杆"; break;
        case NETHER_PORTAL:cout << "传"; break;
        case FURNACE:    cout << "炉"; break;
        case SMITHING_TABLE:cout << "锻"; break;
        default:         cout << "  ";
    }
}

// 绘制实体字符
void drawEntity(EntityType t) {
    switch (t) {
        case PLAYER:    cout << "你"; break;
        case ZOMBIE:    cout << "僵"; break;
        case SKELETON:  cout << "骷"; break;
        case SHEEP:     cout << "羊"; break;
        case PIG:       cout << "猪"; break;
        case CHICKEN:   cout << "**"; break;
        case VILLAGER:  cout << "村"; break;
    }
}

// 绘制UI界面
void drawUI() {
    clear();
    cout << "==== C++我的世界 锻造+附魔+红石完整版 ====" << endl;
    cout << "生命:" << hp << " 饥饿:" << **ger << " Lv:" << level 
    << " 经验:" << exp << " | " << (isNight?"夜晚":"白天") 
    << " " << (isRain?"下雨":"晴天") 
    << " " << (flyMode?"飞行":"行走") << endl;
    cout << "装备:木剑:" << hasSword << " 铁剑:" << hasIronSword 
    << " 钻剑:" << hasDiamondSword << " 合金:" << hasAlloySword << endl;
    cout << "附魔:剑" << swordEnchant << " 镐" << pickEnchant 
    << " 耐久:" << toolDurability << endl;
    cout << "==========================================" << endl;
    
    for (int y = 0; y < HEIGHT; y++) {
        for (int x = 0; x < WIDTH; x++) {
            bool drawn = false;
            if (x == playerX && y == playerY) {
                cout << "!";
                continue;
            }
            for (auto& e : entities) {
                if (e.x == x && e.y == y) {
                    drawEntity(e.type);
                    drawn = true;
                    break;
                }
            }
            if (!drawn) drawBlock(map[y][x]);
        }
        cout << endl;
    }
    
    cout << "\nWASD移动|空格挖掘|1-9放方块|R飞行|T天气|E攻击|U弓箭" << endl;
    cout << "F合成|M附魔|S锻造**|O熔炉烧制|V交易|B睡觉|Q退出" << endl;
}

// 玩家移动
void movePlayer(char c) {
    int nx = playerX, ny = playerY;
    if (c == 'w') ny--;
    if (c == 's') ny++;
    if (c == 'a') nx--;
    if (c == 'd') nx++;
    
    if (nx >= 0 && nx < WIDTH && ny >= 0 && ny < HEIGHT) {
        if (!flyMode && map[ny][nx] != AIR) return;
        playerX = nx;
        playerY = ny;
        **ger = max(0, **ger - 1);
        if (**ger <= 0) hp--;
    }
}

// 挖掘方块
void breakBlock() {
    int b = map[playerY][playerX];
    if (b <= 0) return;
    
    int add = (pickEnchant == 2) ? 2 : 1;
    inv[b] += add;
    exp += (pickEnchant == 1) ? 5 : 2;
    
    if (exp >= level * 12) {
        exp = 0;
        level++;
        hp = 20;
    }
    map[playerY][playerX] = AIR;
    toolDurability -= 5;
    if (toolDurability <= 0) pickEnchant = 0;
}

// 放置方块
void placeBlock(int t) {
    if (map[playerY][playerX] == AIR && inv[t] > 0) {
        map[playerY][playerX] = t;
        inv[t]--;
    }
}

// 生成生物怪物
void spawnCreatures() {
    if (!isNight && rand() % 50 == 0) {
        int x = rand() % WIDTH;
        int y = 9 + rand() % 5;
        EntityType ty = (EntityType)(SHEEP + rand() % 4);
        entities.push_back({x, y, ty, 5});
    }
    if (isNight && rand() % 20 == 0) {
        int x = WIDTH - 2;
        int y = 9 + rand() % 5;
        EntityType ty = rand()%2 ? ZOMBIE : SKELETON;
        entities.push_back({x, y, ty, 8});
    }
}

// 实体AI
void entityAI() {
    for (auto& e : entities) {
        if (e.type == ZOMBIE || e.type == SKELETON) {
            if (e.x > playerX) e.x--;
            else if (e.x < playerX) e.x++;
            if (abs(e.x-playerX)<=1 && abs(e.y-playerY)<=1) {
                int dmg = swordEnchant ? 1 : 2;
                hp -= dmg;
            }
        } else {
            if (rand() % 3 == 0) e.x += rand()%3-1;
            if (e.x<0)e.x=0; if(e.x>=WIDTH)e.x=WIDTH-1;
        }
    }
}

// 近身攻击
void attackNear() {
    for (int i = 0; i < entities.size(); i++) {
        auto& e = entities[i];
        if (abs(e.x-playerX)<=1 && abs(e.y-playerY)<=1) {
            int dmg = 2;
            if(hasIronSword) dmg = 3;
            if(hasDiamondSword) dmg = 5;
            if(hasAlloySword) dmg = 7;
            if(swordEnchant) dmg += 2;
            
            e.hp -= dmg;
            if (e.hp <= 0) {
                if (swordEnchant == 2) inv[WOOD] += 3;
                else inv[WOOD] += 1;
                entities.erase(entities.begin()+i);
                exp += 8;
            }
            **ger = min(20, **ger + 1);
            return;
        }
    }
}

// 弓箭射击
void bowShoot() {
    if (!hasBow) return;
    for (int i = 0; i < entities.size(); i++) {
        auto& e = entities[i];
        int dis = abs(e.x-playerX) + abs(e.y-playerY);
        if (dis <= 6) {
            e.hp -= 4;
            if (e.hp <= 0) {
                entities.erase(entities.begin()+i);
                exp += 6;
            }
            return;
        }
    }
}

// 红石逻辑
void redstoneLogic() {
    if (map[playerY][playerX] == LEVER) {
        isRain = !isRain;
    }
}

// 睡觉
void sleepNight() {
    if (!isNight) return;
    isNight = false;
    isRain = false;
    hp = 20; **ger = 20;
}

// 合成**
void craftMenu() {
    system("cls");
    cout << "【合成】1=木剑 2=弓箭 3=附魔台 4=红石粉 5=拉杆 6=锻造台 7=熔炉" << endl;
    int c; cin >> c;
    if (c == 1 && inv[WOOD] >= 4) { inv[WOOD]-=4; hasSword=true; }
    if (c == 2 && inv[WOOD] >= 2 && inv[COAL] >= 1) { inv[WOOD]-=2; inv[COAL]-=1; hasBow=true; }
    if (c == 3 && inv[DIAMOND] >= 2 && inv[STONE] >= 4) { inv[DIAMOND]-=2; inv[STONE]-=4; inv[ENCHANT_TABLE]++; }
    if (c == 4 && inv[STONE] >= 2) { inv[STONE]-=2; inv[REDSTONE]+=3; }
    if (c == 5 && inv[WOOD] >= 2) { inv[WOOD]-=2; inv[LEVER]++; }
    if (c == 6 && inv[WOOD] >= 6 && inv[IRON] >= 2) { inv[WOOD]-=6; inv[IRON]-=2; inv[SMITHING_TABLE]++; }
    if (c == 7 && inv[STONE] >= 8) { inv[STONE]-=8; inv[FURNACE]++; }
}

// 附魔**
void enchantSystem() {
    if (map[playerY][playerX] != ENCHANT_TABLE) {
        cout << "必须站在附魔台「魔」旁边!"; Sleep(800); return;
    }
    if (exp < 15) {
        cout << "经验不足!"; Sleep(800); return;
    }
    system("cls");
    cout << "【附魔】1=剑附魔 2=镐附魔" << endl;
    int c; cin >> c;
    exp -= 15;
    if (c == 1) swordEnchant = rand()%2 + 1;
    if (c == 2) pickEnchant = rand()%2 + 1;
    toolDurability = 100;
}

// ========== 全新:锻造** + 锻造台 ==========
void smithingSystem() {
    if (map[playerY][playerX] != SMITHING_TABLE) {
        cout << "必须站在锻造台「锻」旁边!"; Sleep(800); return;
    }
    system("cls");
    cout << "==== 锻造** ====" << endl;
    cout << "1=锻造铁剑(铁锭3)" << endl;
    cout << "2=锻造钻石剑(钻石3)" << endl;
    cout << "3=锻造合金剑(金+钻石+红石)" << endl;
    int op; cin >> op;
    
    if(op == 1 && inv[IRON] >= 3){
        inv[IRON] -= 3;
        hasIronSword = true;
        cout << "锻造成功:铁剑!" << endl;
    }
    if(op == 2 && inv[DIAMOND] >= 3){
        inv[DIAMOND] -= 3;
        hasDiamondSword = true;
        cout << "锻造成功:钻石剑!" << endl;
    }
    if(op == 3 && inv[GOLD]>=2 && inv[DIAMOND]>=2 && inv[REDSTONE]>=2){
        inv[GOLD]-=2; inv[DIAMOND]-=2; inv[REDSTONE]-=2;
        hasAlloySword = true;
        cout << "锻造成功:终极合金剑!" << endl;
    }
    Sleep(1000);
}

// ========== 全新:熔炉烧制** ==========
void furnaceSmelt() {
    if (map[playerY][playerX] != FURNACE) {
        cout << "必须站在熔炉「炉」旁边!"; Sleep(800); return;
    }
    system("cls");
    cout << "【熔炉烧制】1=铁矿石烧铁锭 2=金矿石烧金锭" << endl;
    int op; cin >> op;
    if(op == 1 && inv[IRON] >= 2){
        inv[IRON] -= 2;
        inv[IRON] += 1;
        cout << "烧制完成:获得铁锭!" << endl;
    }
    if(op == 2 && inv[GOLD] >= 2){
        inv[GOLD] -= 2;
        inv[GOLD] += 1;
        cout << "烧制完成:获得金锭!" << endl;
    }
    Sleep(1000);
}

// 村民交易
void villagerTrade() {
    system("cls");
    cout << "【村民交易】1=木头换钻石 2=红石换铁锭" << endl;
    int c; cin >> c;
    if (c == 1 && inv[WOOD] >= 10) { inv[WOOD]-=10; inv[DIAMOND]++; }
    if (c == 2 && inv[REDSTONE] >= 5) { inv[REDSTONE]-=5; inv[IRON]++; }
}

// 时间更新
void timeUpdate() {
    timeTick++;
    if (timeTick > 60) {
        isNight = !isNight;
        timeTick = 0;
    }
}

int main() {
    srand((unsigned)time(NULL));
    generateTerrain();
    
    while (true) {
        drawUI();
        timeUpdate();
        spawnCreatures();
        entityAI();
        redstoneLogic();
        
        if (_kbhit()) {
            char k = _getch();
            if (k == 'q') break;
            if (k == 'w'||k=='a'||k=='s'||k=='d') movePlayer(k);
            if (k == ' ') breakBlock();
            if (k >= '1' && k <= '9') placeBlock(k - '0');
            if (k == 'r' || k == 'R') flyMode = !flyMode;
            if (k == 't' || k == 'T') isRain = !isRain;
            if (k == 'e' || k == 'E') attackNear();
            if (k == 'u' || k == 'U') bowShoot();
            if (k == 'b' || k == 'B') sleepNight();
            if (k == 'f' || k == 'F') craftMenu();
            if (k == 'm' || k == 'M') enchantSystem();
            if (k == 'v' || k == 'V') villagerTrade();
            // 新增快捷键
            if (k == 's' || k == 'S') smithingSystem();
            if (k == 'o' || k == 'O') furnaceSmelt();
        }
        
        if (hp <= 0) {
            clear();
            cout << "你**亡了!游戏结束!" << endl;
            Sleep(3000);
            break;
        }
        Sleep(110);
    }
    return 0;
}

#include <iostream>
#include <conio.h>
#include <windows.h>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

// 地图尺寸
const int WIDTH = 40;
const int HEIGHT = 22;

// 方块ID
enum Block {
    AIR, DIRT, STONE, WOOD, LEAF, COAL, IRON, GOLD, DIAMOND,
    TORCH, BED, CRAFT_TABLE, ENCHANT_TABLE, REDSTONE, REDSTONE_LAMP,
    LEVER, NETHER_PORTAL, FURNACE, SMITHING_TABLE
};

// 实体类型
enum EntityType { PLAYER, ZOMBIE, SKELETON, SHEEP, PIG, CHICKEN, VILLAGER };

// 实体结构体
struct Entity {
    int x, y;
    EntityType type;
    int hp;
};

// 玩家全局数据
int map[HEIGHT][WIDTH] = { 0 };
int playerX = WIDTH / 2, playerY = 10;
int hp = 20, **ger = 20, exp = 0, level = 1;
int inv[30] = { 0 };

// 装备 & 锻造
bool hasSword = false, hasBow = false;
int swordEnchant = 0;
int pickEnchant = 0;
int toolDurability = 100;
bool hasIronSword = false;
bool hasDiamondSword = false;
bool hasAlloySword = false;

// 游戏状态
bool isNight = false;
bool isRain = false;
bool flyMode = false;
int timeTick = 0;

// 实体列表
vector<Entity> entities;

// 清屏
void clear() { system("cls"); }

// 随机地形生成
void generateTerrain() {
    for (int x = 0; x < WIDTH; x++) {
        int h = 11 + rand() % 4;
        for (int y = h; y < HEIGHT; y++) map[y][x] = DIRT;
        for (int y = h - 3; y < h; y++) map[y][x] = STONE;
    }
    
    // 生成树木
    for (int i = 0; i < 12; i++) {
        int x = rand() % WIDTH;
        map[8][x] = WOOD; map[7][x] = WOOD;
        map[6][x-1] = LEAF; map[6][x] = LEAF; map[6][x+1] = LEAF;
        map[5][x] = LEAF;
    }
    
    // 生成矿物
    for (int x = 0; x < WIDTH; x++) {
        for (int y = 0; y < 11; y++) {
            if (map[y][x] == STONE) {
                int r = rand() % 100;
                if (r < 4) map[y][x] = COAL;
                else if (r < 7) map[y][x] = IRON;
                else if (r < 9) map[y][x] = GOLD;
                else if (r < 11) map[y][x] = DIAMOND;
                else if (r < 14) map[y][x] = REDSTONE;
            }
        }
    }
    
    // 固定生成功能**方块
    map[10][5]  = ENCHANT_TABLE;
    map[10][30] = NETHER_PORTAL;
    map[12][15] = LEVER;
    map[12][18] = REDSTONE_LAMP;
    map[13][8]  = FURNACE;
    map[13][12] = SMITHING_TABLE;
}

// 绘制方块字符
void drawBlock(int b) {
    switch (b) {
        case AIR:        cout << "  "; break;
        case DIRT:       cout << "土"; break;
        case STONE:      cout << "石"; break;
        case WOOD:       cout << "木"; break;
        case LEAF:       cout << "叶"; break;
        case COAL:       cout << "煤"; break;
        case IRON:       cout << "铁"; break;
        case GOLD:       cout << "金"; break;
        case DIAMOND:    cout << "钻"; break;
        case TORCH:      cout << "火"; break;
        case BED:        cout << "床"; break;
        case CRAFT_TABLE:cout << "台"; break;
        case ENCHANT_TABLE:cout << "魔"; break;
        case REDSTONE:   cout << "红"; break;
        case REDSTONE_LAMP:cout << (isRain?"亮":"暗"); break;
        case LEVER:      cout << "杆"; break;
        case NETHER_PORTAL:cout << "传"; break;
        case FURNACE:    cout << "炉"; break;
        case SMITHING_TABLE:cout << "锻"; break;
        default:         cout << "  ";
    }
}

// 绘制实体字符
void drawEntity(EntityType t) {
    switch (t) {
        case PLAYER:    cout << "你"; break;
        case ZOMBIE:    cout << "僵"; break;
        case SKELETON:  cout << "骷"; break;
        case SHEEP:     cout << "羊"; break;
        case PIG:       cout << "猪"; break;
        case CHICKEN:   cout << "**"; break;
        case VILLAGER:  cout << "村"; break;
    }
}

// 绘制UI界面
void drawUI() {
    clear();
    cout << "==== C++我的世界 锻造+附魔+红石完整版 ====" << endl;
    cout << "生命:" << hp << " 饥饿:" << **ger << " Lv:" << level 
    << " 经验:" << exp << " | " << (isNight?"夜晚":"白天") 
    << " " << (isRain?"下雨":"晴天") 
    << " " << (flyMode?"飞行":"行走") << endl;
    cout << "装备:木剑:" << hasSword << " 铁剑:" << hasIronSword 
    << " 钻剑:" << hasDiamondSword << " 合金:" << hasAlloySword << endl;
    cout << "附魔:剑" << swordEnchant << " 镐" << pickEnchant 
    << " 耐久:" << toolDurability << endl;
    cout << "==========================================" << endl;
    
    for (int y = 0; y < HEIGHT; y++) {
        for (int x = 0; x < WIDTH; x++) {
            bool drawn = false;
            if (x == playerX && y == playerY) {
                cout << "!";
                continue;
            }
            for (auto& e : entities) {
                if (e.x == x && e.y == y) {
                    drawEntity(e.type);
                    drawn = true;
                    break;
                }
            }
            if (!drawn) drawBlock(map[y][x]);
        }
        cout << endl;
    }
    
    cout << "\nWASD移动|空格挖掘|1-9放方块|R飞行|T天气|E攻击|U弓箭" << endl;
    cout << "F合成|M附魔|S锻造**|O熔炉烧制|V交易|B睡觉|Q退出" << endl;
}

// 玩家移动
void movePlayer(char c) {
    int nx = playerX, ny = playerY;
    if (c == 'w') ny--;
    if (c == 's') ny++;
    if (c == 'a') nx--;
    if (c == 'd') nx++;
    
    if (nx >= 0 && nx < WIDTH && ny >= 0 && ny < HEIGHT) {
        if (!flyMode && map[ny][nx] != AIR) return;
        playerX = nx;
        playerY = ny;
        **ger = max(0, **ger - 1);
        if (**ger <= 0) hp--;
    }
}

// 挖掘方块
void breakBlock() {
    int b = map[playerY][playerX];
    if (b <= 0) return;
    
    int add = (pickEnchant == 2) ? 2 : 1;
    inv[b] += add;
    exp += (pickEnchant == 1) ? 5 : 2;
    
    if (exp >= level * 12) {
        exp = 0;
        level++;
        hp = 20;
    }
    map[playerY][playerX] = AIR;
    toolDurability -= 5;
    if (toolDurability <= 0) pickEnchant = 0;
}

// 放置方块
void placeBlock(int t) {
    if (map[playerY][playerX] == AIR && inv[t] > 0) {
        map[playerY][playerX] = t;
        inv[t]--;
    }
}

// 生成生物怪物
void spawnCreatures() {
    if (!isNight && rand() % 50 == 0) {
        int x = rand() % WIDTH;
        int y = 9 + rand() % 5;
        EntityType ty = (EntityType)(SHEEP + rand() % 4);
        entities.push_back({x, y, ty, 5});
    }
    if (isNight && rand() % 20 == 0) {
        int x = WIDTH - 2;
        int y = 9 + rand() % 5;
        EntityType ty = rand()%2 ? ZOMBIE : SKELETON;
        entities.push_back({x, y, ty, 8});
    }
}

// 实体AI
void entityAI() {
    for (auto& e : entities) {
        if (e.type == ZOMBIE || e.type == SKELETON) {
            if (e.x > playerX) e.x--;
            else if (e.x < playerX) e.x++;
            if (abs(e.x-playerX)<=1 && abs(e.y-playerY)<=1) {
                int dmg = swordEnchant ? 1 : 2;
                hp -= dmg;
            }
        } else {
            if (rand() % 3 == 0) e.x += rand()%3-1;
            if (e.x<0)e.x=0; if(e.x>=WIDTH)e.x=WIDTH-1;
        }
    }
}

// 近身攻击
void attackNear() {
    for (int i = 0; i < entities.size(); i++) {
        auto& e = entities[i];
        if (abs(e.x-playerX)<=1 && abs(e.y-playerY)<=1) {
            int dmg = 2;
            if(hasIronSword) dmg = 3;
            if(hasDiamondSword) dmg = 5;
            if(hasAlloySword) dmg = 7;
            if(swordEnchant) dmg += 2;
            
            e.hp -= dmg;
            if (e.hp <= 0) {
                if (swordEnchant == 2) inv[WOOD] += 3;
                else inv[WOOD] += 1;
                entities.erase(entities.begin()+i);
                exp += 8;
            }
            **ger = min(20, **ger + 1);
            return;
        }
    }
}

// 弓箭射击
void bowShoot() {
    if (!hasBow) return;
    for (int i = 0; i < entities.size(); i++) {
        auto& e = entities[i];
        int dis = abs(e.x-playerX) + abs(e.y-playerY);
        if (dis <= 6) {
            e.hp -= 4;
            if (e.hp <= 0) {
                entities.erase(entities.begin()+i);
                exp += 6;
            }
            return;
        }
    }
}

// 红石逻辑
void redstoneLogic() {
    if (map[playerY][playerX] == LEVER) {
        isRain = !isRain;
    }
}

// 睡觉
void sleepNight() {
    if (!isNight) return;
    isNight = false;
    isRain = false;
    hp = 20; **ger = 20;
}

// 合成**
void craftMenu() {
    system("cls");
    cout << "【合成】1=木剑 2=弓箭 3=附魔台 4=红石粉 5=拉杆 6=锻造台 7=熔炉" << endl;
    int c; cin >> c;
    if (c == 1 && inv[WOOD] >= 4) { inv[WOOD]-=4; hasSword=true; }
    if (c == 2 && inv[WOOD] >= 2 && inv[COAL] >= 1) { inv[WOOD]-=2; inv[COAL]-=1; hasBow=true; }
    if (c == 3 && inv[DIAMOND] >= 2 && inv[STONE] >= 4) { inv[DIAMOND]-=2; inv[STONE]-=4; inv[ENCHANT_TABLE]++; }
    if (c == 4 && inv[STONE] >= 2) { inv[STONE]-=2; inv[REDSTONE]+=3; }
    if (c == 5 && inv[WOOD] >= 2) { inv[WOOD]-=2; inv[LEVER]++; }
    if (c == 6 && inv[WOOD] >= 6 && inv[IRON] >= 2) { inv[WOOD]-=6; inv[IRON]-=2; inv[SMITHING_TABLE]++; }
    if (c == 7 && inv[STONE] >= 8) { inv[STONE]-=8; inv[FURNACE]++; }
}

// 附魔**
void enchantSystem() {
    if (map[playerY][playerX] != ENCHANT_TABLE) {
        cout << "必须站在附魔台「魔」旁边!"; Sleep(800); return;
    }
    if (exp < 15) {
        cout << "经验不足!"; Sleep(800); return;
    }
    system("cls");
    cout << "【附魔】1=剑附魔 2=镐附魔" << endl;
    int c; cin >> c;
    exp -= 15;
    if (c == 1) swordEnchant = rand()%2 + 1;
    if (c == 2) pickEnchant = rand()%2 + 1;
    toolDurability = 100;
}

// ========== 全新:锻造** + 锻造台 ==========
void smithingSystem() {
    if (map[playerY][playerX] != SMITHING_TABLE) {
        cout << "必须站在锻造台「锻」旁边!"; Sleep(800); return;
    }
    system("cls");
    cout << "==== 锻造** ====" << endl;
    cout << "1=锻造铁剑(铁锭3)" << endl;
    cout << "2=锻造钻石剑(钻石3)" << endl;
    cout << "3=锻造合金剑(金+钻石+红石)" << endl;
    int op; cin >> op;
    
    if(op == 1 && inv[IRON] >= 3){
        inv[IRON] -= 3;
        hasIronSword = true;
        cout << "锻造成功:铁剑!" << endl;
    }
    if(op == 2 && inv[DIAMOND] >= 3){
        inv[DIAMOND] -= 3;
        hasDiamondSword = true;
        cout << "锻造成功:钻石剑!" << endl;
    }
    if(op == 3 && inv[GOLD]>=2 && inv[DIAMOND]>=2 && inv[REDSTONE]>=2){
        inv[GOLD]-=2; inv[DIAMOND]-=2; inv[REDSTONE]-=2;
        hasAlloySword = true;
        cout << "锻造成功:终极合金剑!" << endl;
    }
    Sleep(1000);
}

// ========== 全新:熔炉烧制** ==========
void furnaceSmelt() {
    if (map[playerY][playerX] != FURNACE) {
        cout << "必须站在熔炉「炉」旁边!"; Sleep(800); return;
    }
    system("cls");
    cout << "【熔炉烧制】1=铁矿石烧铁锭 2=金矿石烧金锭" << endl;
    int op; cin >> op;
    if(op == 1 && inv[IRON] >= 2){
        inv[IRON] -= 2;
        inv[IRON] += 1;
        cout << "烧制完成:获得铁锭!" << endl;
    }
    if(op == 2 && inv[GOLD] >= 2){
        inv[GOLD] -= 2;
        inv[GOLD] += 1;
        cout << "烧制完成:获得金锭!" << endl;
    }
    Sleep(1000);
}

// 村民交易
void villagerTrade() {
    system("cls");
    cout << "【村民交易】1=木头换钻石 2=红石换铁锭" << endl;
    int c; cin >> c;
    if (c == 1 && inv[WOOD] >= 10) { inv[WOOD]-=10; inv[DIAMOND]++; }
    if (c == 2 && inv[REDSTONE] >= 5) { inv[REDSTONE]-=5; inv[IRON]++; }
}

// 时间更新
void timeUpdate() {
    timeTick++;
    if (timeTick > 60) {
        isNight = !isNight;
        timeTick = 0;
    }
}

int main() {
    srand((unsigned)time(NULL));
    generateTerrain();
    
    while (true) {
        drawUI();
        timeUpdate();
        spawnCreatures();
        entityAI();
        redstoneLogic();
        
        if (_kbhit()) {
            char k = _getch();
            if (k == 'q') break;
            if (k == 'w'||k=='a'||k=='s'||k=='d') movePlayer(k);
            if (k == ' ') breakBlock();
            if (k >= '1' && k <= '9') placeBlock(k - '0');
            if (k == 'r' || k == 'R') flyMode = !flyMode;
            if (k == 't' || k == 'T') isRain = !isRain;
            if (k == 'e' || k == 'E') attackNear();
            if (k == 'u' || k == 'U') bowShoot();
            if (k == 'b' || k == 'B') sleepNight();
            if (k == 'f' || k == 'F') craftMenu();
            if (k == 'm' || k == 'M') enchantSystem();
            if (k == 'v' || k == 'V') villagerTrade();
            // 新增快捷键
            if (k == 's' || k == 'S') smithingSystem();
            if (k == 'o' || k == 'O') furnaceSmelt();
        }
        
        if (hp <= 0) {
            clear();
            cout << "你**亡了!游戏结束!" << endl;
            Sleep(3000);
            break;
        }
        Sleep(110);
    }
    return 0;
}


0
我要回答