🎮ArcadeLab

进阶小黑屋生存

by NovaViper55
171 lines5.4 KB
▶ Play
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>进阶小黑屋生存</title>
    <style>
        *{background:#111;color:#eee;font-family:Microsoft YaHei;}
        body{max-width:720px;margin:30px auto;padding:12px;}
        .log{height:340px;overflow-y:auto;border:1px #555 solid;padding:10px;margin-bottom:15px;white-space:pre-line;}
        button{padding:8px 12px;margin:5px 3px;border:1px #666 solid;background:#222;cursor:pointer;}
        button:disabled{opacity:0.25;cursor:not-allowed;}
        .info{margin:10px 0;color:#bbb;line-height:1.6;}
        .group{margin:8px 0;}
    </style>
</head>
<body>
<div class="info">
【资源面板】<br>
木头:<span id="wood">5</span>|食物:<span id="food">3</span><br>
火堆:<span id="fire">熄灭</span>|小屋:<span id="house">未建造</span>|武器:<span id="weapon">无</span>
</div>

<div class="log" id="gameLog">你在漆黑冰冷的小屋中苏醒,身边散落少量木头与存粮,生存之旅开始了。\n</div>

<div class="group">
    <button id="btnFire">生火(2木)</button>
    <button id="btnWood">外出伐木(火堆开启)</button>
    <button id="btnBuild">建造小屋(10木)</button>
</div>
<div class="group">
    <button id="btnHunt">出门狩猎(需火堆,消耗1食物)</button>
    <button id="btnCraft">制作石矛(8木头,解锁狩猎打怪)</button>
    <button id="btnExplore">深入荒野探索(需要小屋)</button>
</div>

<script>
// 游戏存档数据
let save = {
    wood:5,
    food:3,
    fire:false,
    house:false,
    weapon:false // 石矛
}

// DOM绑定
const logBox = document.getElementById('gameLog');
const woodText = document.getElementById('wood');
const foodText = document.getElementById('food');
const fireText = document.getElementById('fire');
const houseText = document.getElementById('house');
const weaponText = document.getElementById('weapon');

const btnFire = document.getElementById('btnFire');
const btnWood = document.getElementById('btnWood');
const btnBuild = document.getElementById('btnBuild');
const btnHunt = document.getElementById('btnHunt');
const btnCraft = document.getElementById('btnCraft');
const btnExplore = document.getElementById('btnExplore');

// 日志追加
function addLog(str){
    logBox.innerHTML += str + '\n';
    logBox.scrollTop = logBox.scrollHeight;
}

// 刷新全部UI
function updateUI(){
    woodText.innerText = save.wood;
    foodText.innerText = save.food;
    fireText.innerText = save.fire ? "燃烧中" : "熄灭";
    houseText.innerText = save.house ? "已建成" : "未建造";
    weaponText.innerText = save.weapon ? "石矛" : "无";

    // 按钮锁定规则
    btnFire.disabled = save.fire || save.wood < 2;
    btnWood.disabled = !save.fire;
    btnBuild.disabled = save.wood < 10;
    btnCraft.disabled = save.wood < 8 || save.weapon;
    btnHunt.disabled = !save.fire || save.food < 1;
    btnExplore.disabled = !save.house;
}

// 1.生火
btnFire.onclick = ()=>{
    save.wood -= 2;
    save.fire = true;
    addLog("你点燃木柴,屋内暖意蔓延,黑夜不再刺骨。");
    updateUI();
}

// 2.伐木
btnWood.onclick = ()=>{
    let gain = Math.floor(Math.random()*3)+1;
    save.wood += gain;
    addLog(`进山伐木,收获${gain}根木头。`);
    updateUI();
}

//3.造小屋
btnBuild.onclick = ()=>{
    save.wood -= 10;
    save.house = true;
    addLog("耗费木料搭建稳固木屋,从此可以远行探索荒野。");
    updateUI();
}

//4.制作武器
btnCraft.onclick = ()=>{
    save.wood -=8;
    save.weapon = true;
    addLog("打磨石块、捆绑木杆,成功造出狩猎石矛!狩猎效率大幅提升。");
    updateUI();
}

//5.狩猎
btnHunt.onclick = ()=>{
    save.food -=1;
    if(save.weapon){
        let res = Math.random();
        if(res>0.3){
            let get = Math.floor(Math.random()*5)+3;
            save.food += get;
            addLog(`持矛狩猎成功!猎杀野兽,获得${get}份肉食。`);
        }else{
            addLog("猎物逃窜,本次狩猎空手而归。");
        }
    }else{
        let res = Math.random();
        if(res>0.7){
            save.food +=2;
            addLog("徒手侥幸抓到小动物,收获2份食物。");
        }else{
            addLog("空手捕猎失败,白白消耗存粮。");
        }
    }
    updateUI();
}

//6.荒野探索(随机资源/遇怪)
btnExplore.onclick = ()=>{
    let rand = Math.random();
    if(rand < 0.35){
        // 捡到物资
        let w = Math.floor(Math.random()*6)+2;
        let f = Math.floor(Math.random()*4)+1;
        save.wood +=w;
        save.food +=f;
        addLog(`野外发现遗弃物资,木头+${w},食物+${f}`);
    }else if(rand < 0.65){
        //遭遇野兽战斗
        if(save.weapon){
            let drop = Math.floor(Math.random()*5)+4;
            save.food += drop;
            addLog("遭遇野狼,依靠石矛击杀,获得大量肉食"+drop+"份");
        }else{
            let loseFood = Math.min(save.food,2);
            save.food -= loseFood;
            addLog(`遭遇猛兽无武器逃跑,慌乱遗失${loseFood}份食物。`);
        }
    }else{
        addLog("四处搜寻一无所获,平安返回小屋。");
    }
    updateUI();
}

updateUI();
</script>
</body>
</html>

Game Source: 进阶小黑屋生存

Creator: NovaViper55

Libraries: none

Complexity: moderate (171 lines, 5.4 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: -novaviper55-mq0l4pvj" to link back to the original. Then publish at arcadelab.ai/publish.