🎮ArcadeLab

幽灵模拟器

by LunarPanda25
132 lines4.0 KB
▶ Play
<!-- ARCADELAB HEADER -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>幽灵模拟器</title>
    <style>
        *{box-sizing:border-box;font-family:system-ui}
        body{background:#1a1a22;color:#fff;padding:10px;margin:0}
        .container{max-width:900px;margin:0 auto}
        .floor-box{border:1px solid #666;padding:10px;margin:8px 0;border-radius:8px;background:#272733}
        .control{margin:12px 0}
        button{padding:8px 14px;margin:3px;background:#444;color:#fff;border:none;border-radius:4px;cursor:pointer}
        button:hover{background:#666}
        .info{background:#333;padding:10px;border-radius:6px;margin:10px 0}
    </style>
</head>
<body>
<div class="container">
    <h1>👻幽灵模拟器</h1>
    <div class="info">
        <div>剩余时间:<span id="timer">300</span>秒(5分钟)</div>
        <div>在场客人:<span id="guestAlive">15</span>|已驱离:<span id="guestRun">0</span>|意外吓死:<span id="guestDead">0</span></div>
        <div id="rank">当前评级:待结算</div>
        <div id="gameTip">提示:选择楼层,附身家具增加客人恐惧,不要把人吓死!</div>
    </div>

    <div class="control">
        <button onclick="startGame()">开始游戏</button>
        <button onclick="resetGame()">重置</button>
    </div>

    <div class="floor-box">
        <h3>1F 客厅 / 厨房 / 花园</h3>
        <button onclick="haunt(1)">附身沙发吓人</button>
        <button onclick="haunt(1)">晃动厨具</button>
    </div>
    <div class="floor-box">
        <h3>2F 餐厅 / 浴室 / 书房</h3>
        <button onclick="haunt(2)">餐具自行移动</button>
        <button onclick="haunt(2)">书本翻页</button>
    </div>
    <div class="floor-box">
        <h3>3F 两间卧室</h3>
        <button onclick="haunt(3)">被子抖动</button>
    </div>
    <div class="floor-box">
        <h3>4F 阁楼</h3>
        <button onclick="haunt(4)">阁楼杂物响动</button>
    </div>
</div>

<script>
//游戏数据
let timeLeft = 300;
let alive =15;
let run=0;
let dead=0;
let gameOn=false;
let timerId=null;

function startGame(){
    if(gameOn)return;
    gameOn=true;
    timerId=setInterval(countDown,1000);
    document.getElementById("gameTip").innerText="游戏开始!操控幽灵制造异象,吓走客人";
}
function countDown(){
    timeLeft--;
    document.getElementById("timer").innerText=timeLeft;
    if(timeLeft<=0){gameOver();}
}

//附身吓人
function haunt(floor){
    if(!gameOn)return;
    if(alive<=0)return;
    //随机:吓走/吓死
    let r=Math.random();
    if(r<0.25){
        //客人被吓跑
        alive--;run++;
    }else if(r>0.88){
        //意外吓死
        alive--;dead++;
    }
    updateUI();
    checkLose();
}

function updateUI(){
    document.getElementById("guestAlive").innerText=alive;
    document.getElementById("guestRun").innerText=run;
    document.getElementById("guestDead").innerText=dead;
}

function checkLose(){
    //吓死11人以上直接失败
    if(dead>=11){
        gameOver("你害死太多客人,游戏失败!");
    }
}

function gameOver(msg=""){
    gameOn=false;
    clearInterval(timerId);
    let realRun=run;
    if(dead>=5) realRun-=1;
    if(dead>=10) realRun-=2;

    if(realRun<=0) finalRank="失败";
    else if(realRun<=5) finalRank="C级";
    else if(realRun<=10) finalRank="B级";
    else if(realRun<=14) finalRank="A级";
    else finalRank="S级";

    document.getElementById("rank").innerText=`结算评级:${finalRank}`;
    document.getElementById("gameTip").innerText=msg||"时间结束,游戏结算";
}

function resetGame(){
    clearInterval(timerId);
    timeLeft=300;alive=15;run=0;dead=0;gameOn=false;
    updateUI();
    document.getElementById("timer").innerText=300;
    document.getElementById("rank").innerText="当前评级:待结算";
    document.getElementById("gameTip").innerText="提示:选择楼层,附身家具增加客人恐惧,不要把人吓死!";
}
</script>
</body>
</html>

Game Source: 幽灵模拟器

Creator: LunarPanda25

Libraries: none

Complexity: moderate (132 lines, 4.0 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: game-lunarpanda25" to link back to the original. Then publish at arcadelab.ai/publish.