🎮ArcadeLab

摸金探秘

by MysticPanda36
278 lines5.8 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>
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  background: #111;
  color: #fff;
  font-family: "Microsoft YaHei", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
}
#gameContainer {
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
  background: #222;
  border: 2px solid #888;
  position: relative;
  overflow: hidden;
}
.cell {
  position: absolute;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  border: 1px solid #444;
}
.player {
  background: rgba(66, 180, 255, 0.3);
}
.box {
  background: rgba(255, 215, 0, 0.2);
}
.gold {
  background: rgba(255, 215, 0, 0.5);
}
.trap {
  background: rgba(255, 0, 0, 0.3);
}
.exit {
  background: rgba(0, 255, 0, 0.3);
}
#ui {
  margin-top: 10px;
  width: 100%;
  max-width: 420px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#items {
  display: flex;
  gap: 6px;
}
.itemBtn {
  padding: 6px 10px;
  font-size: 14px;
  background: #444;
  color: #fff;
  border: 1px solid #888;
  border-radius: 4px;
}
.itemBtn:disabled {
  opacity: 0.4;
}
#status {
  font-size: 14px;
}
</style>
</head>
<body>
<h2>摸金探秘</h2>
<div id="gameContainer"></div>
<div id="ui">
  <div id="items">
    <button class="itemBtn" id="bombBtn" disabled>清障符</button>
    <button class="itemBtn" id="detectBtn" disabled>寻踪眼</button>
  </div>
  <div id="status">分数:0 | 生命:❤️❤️❤️</div>
</div>

<script>
const W = 10, H = 10;
const cellSize = 40;
const container = document.getElementById("gameContainer");
container.style.width = W * cellSize + "px";
container.style.height = H * cellSize + "px";

let map = [];
let player = {x:0,y:0};
let exitPos = {x:0,y:0};
let score = 0;
let life = 3;
let hasBomb = false, hasDetect = false;

const bombBtn = document.getElementById("bombBtn");
const detectBtn = document.getElementById("detectBtn");
const statusEl = document.getElementById("status");

function rand(min,max){ return Math.floor(Math.random()*(max-min+1))+min; }

function initMap(){
  map = [];
  for(let y=0;y<H;y++){
    let row = [];
    for(let x=0;x<W;x++){
      row.push(0);
    }
    map.push(row);
  }
  // 玩家起点
  player.x=0; player.y=0;
  map[0][0] = 1;
  // 出口
  exitPos.x=W-1; exitPos.y=H-1;
  map[H-1][W-1] = 2;
  // 普通宝箱
  for(let i=0;i<8;i++){
    let x=rand(1,W-2), y=rand(1,H-2);
    if(map[y][x]===0) map[y][x]=3;
  }
  // 金宝箱
  for(let i=0;i<3;i++){
    let x=rand(1,W-2), y=rand(1,H-2);
    if(map[y][x]===0) map[y][x]=4;
  }
  // 陷阱
  for(let i=0;i<10;i++){
    let x=rand(1,W-2), y=rand(1,H-2);
    if(map[y][x]===0) map[y][x]=5;
  }
  // 道具
  let bx=rand(1,W-2), by=rand(1,H-2);
  if(map[by][bx]===0) map[by][bx]=6;
  let dx=rand(1,W-2), dy=rand(1,H-2);
  if(map[dy][dx]===0) map[dy][dx]=7;
}

function render(){
  container.innerHTML="";
  for(let y=0;y<H;y++){
    for(let x=0;x<W;x++){
      let d = document.createElement("div");
      d.className = "cell";
      d.style.left = x*cellSize+"px";
      d.style.top = y*cellSize+"px";
      let t = map[y][x];
      if(x===player.x && y===player.y){
        d.classList.add("player");
        d.textContent="👤";
      }else if(t===2){
        d.classList.add("exit");
        d.textContent="🚪";
      }else if(t===3){
        d.classList.add("box");
        d.textContent="📦";
      }else if(t===4){
        d.classList.add("gold");
        d.textContent="💎";
      }else if(t===5){
        d.classList.add("trap");
        d.textContent="⚠️";
      }else if(t===6){
        d.textContent="💣";
      }else if(t===7){
        d.textContent="👁️";
      }
      container.appendChild(d);
    }
  }
  let heart = "❤️".repeat(life) + "🖤".repeat(3-life);
  statusEl.textContent = `分数:${score} | 生命:${heart}`;
  bombBtn.disabled = !hasBomb;
  detectBtn.disabled = !hasDetect;
}

function move(dx, dy){
  let nx = player.x+dx;
  let ny = player.y+dy;
  if(nx<0||nx>=W||ny<0||ny>=H) return;
  player.x=nx; player.y=ny;
  let t = map[ny][nx];
  if(t===2){
    alert("恭喜通关!当前分数:"+score);
    nextLevel();
    return;
  }
  if(t===3){
    score+=10; map[ny][nx]=0;
  }else if(t===4){
    score+=30; map[ny][nx]=0;
  }else if(t===5){
    life--; map[ny][nx]=0;
    if(life<=0){
      alert("探险失败!最终分数:"+score);
      resetGame();
      return;
    }
  }else if(t===6){
    hasBomb=true; map[ny][nx]=0;
  }else if(t===7){
    hasDetect=true; map[ny][nx]=0;
  }
  render();
}

function nextLevel(){
  score+=50;
  life=3;
  hasBomb=false; hasDetect=false;
  initMap();
  render();
}

function resetGame(){
  score=0; life=3;
  hasBomb=false; hasDetect=false;
  initMap();
  render();
}

// 滑动控制
let startX=0, startY=0;
container.addEventListener("touchstart",e=>{
  startX=e.touches[0].clientX;
  startY=e.touches[0].clientY;
});
container.addEventListener("touchend",e=>{
  let endX=e.changedTouches[0].clientX;
  let endY=e.changedTouches[0].clientY;
  let dx=endX-startX;
  let dy=endY-startY;
  if(Math.abs(dx)>Math.abs(dy)){
    if(dx>30) move(1,0);
    else if(dx<-30) move(-1,0);
  }else{
    if(dy>30) move(0,1);
    else if(dy<-30) move(0,-1);
  }
});

// 道具按钮
bombBtn.addEventListener("click",()=>{
  if(!hasBomb) return;
  hasBomb=false;
  for(let y=0;y<H;y++){
    for(let x=0;x<W;x++){
      if(map[y][x]===5) map[y][x]=0;
    }
  }
  render();
});
detectBtn.addEventListener("click",()=>{
  if(!hasDetect) return;
  hasDetect=false;
  alert("寻踪眼已生效,全场陷阱清晰可见!");
  render();
});

initMap();
render();
</script>

</body>
</html>

Game Source: 摸金探秘

Creator: MysticPanda36

Libraries: none

Complexity: complex (278 lines, 5.8 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: -mysticpanda36" to link back to the original. Then publish at arcadelab.ai/publish.