蜜汁小游戏
cuowu错误
2026年10月23日 13:51

<!DOCTYPE html>

<html lang="zh-CN">

<head>

<meta charset="UTF-8">

<title>寻宝小队</title>

<style>

*{box-sizing:border-box;font-family:system-ui}

body{max-width:700px;margin:20px auto;padding:15px;background:#1a222c;color:#fff;font-size:17px}

#log{height:320px;overflow-y:auto;background:#2c3848;padding:12px;border-radius:8px;border:1px solid #555}

#inputBox{margin-top:12px;display:flex;gap:8px}

#cmd{flex:1;padding:10px;border-radius:6px;border:none;font-size:16px}

button{padding:10px 16px;background:#348eda;color:white;border:none;border-radius:6px;cursor:pointer}

.inv{margin-top:10px;background:#2c3848;padding:10px;border-radius:8px}

</style>

</head>

<body>

<div id="log">欢迎来到寻宝小队!<br>

指令:look(查看周围)、go 方向、take 物品名、bag(打开背包)、open 宝箱<br>

当前位置:森林入口<br>

</div>

<div class="inv">背包:<span id="bag">空</span></div>

<div id="inputBox">

<input id="cmd" placeholder="输入指令,例如:look">

<button onclick="runCmd()">执行</button>

</div>

<script>

// 游戏数据

let game = {

place:"森林入口",

bag:[],

treasureFound:0,

map:{

"森林入口":{

desc:"大树遮天,前方有小路,东边通往山洞,北边通往小溪。地上有一把火把。",

item:"火把",

next:{"东":"山洞","北":"小溪"}

},

"山洞":{

desc:"黑漆漆的洞穴,没有火把看不清。深处有一个上锁的宝箱。",

item:null,

hasChest:true,

next:{"西":"森林入口"}

},

"小溪":{

desc:"清澈小溪,石头底下藏着东西。向南回到森林入口。一只小狐狸在旁边看着你。",

item:"宝石碎片",

next:{"南":"森林入口"}

}

}

}

// 输出文字

function print(text){

const log = document.getElementById("log");

log.innerHTML += text + "<br>";

log.scrollTop = log.scrollHeight;

}

// 更新背包显示

function updateBag(){

document.getElementById("bag").innerText = game.bag.length>0 ? game.bag.join("、") : "空";

}

// 执行指令

function runCmd(){

const cmd = document.getElementById("cmd").value.trim().toLowerCase();

document.getElementById("cmd").value = "";

if(!cmd) return;

print("> "+cmd);

const now = game.map[game.place];

let word = cmd.split(" ");

if(word[0]==="look"){

print(now.desc);

if(now.item) print(`这里有:${now.item}`);

if(now.hasChest) print(`这里有:宝箱`);

}

else if(word[0]==="go"){

let target = now.next[word[1]];

//山洞黑暗判定,必须拥有火把

if(target === "山洞" && !game.bag.includes("火把")){

print("❌山洞太黑!没有火把,不敢进去!");

return;

}

if(target){

game.place = target;

print(`你走到了【${target}】`);

print(game.map[target].desc);

}else{

print("这个方向走不通!");

}

}

else if(word[0]==="take"){

let want = word.slice(1).join(" ");

if(now.item && now.item === want){

game.bag.push(want);

print(`✅拿到了【${want}】放进背包!`);

now.item = null;

updateBag();

}else{

print("没有这个东西!");

}

}

else if(word[0]==="open"){

if(game.place === "山洞" && now.hasChest){

if(game.bag.includes("旧钥匙")){

print("🔓你用旧钥匙打开宝箱!获得【宝藏皇冠】!");

game.bag.push("宝藏皇冠");

now.hasChest = false;

updateBag();

print("🎉🎉恭喜寻宝成功!你找到了传说宝藏!");

}else{

print("🔒宝箱锁死了,需要钥匙!");

}

}else{

print("这里没有宝箱!");

}

}

else if(word[0]==="bag"){

print("📦背包:"+(game.bag.length>0 ? game.bag.join("、"):"空空如也"));

}

else{

print("❓看不懂指令!可用:look / go 东 / take 火把 / bag / open 宝箱");

}

}

</script>

</body>

</html>