示例示例成品 · 不是你的AI 按示范写的,看个样子
==[代码]==
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>森林寻宝迷宫</title>
<style>
body { display:flex; flex-direction:column; align-items:center; justify-content:center; height:100vh; margin:0; background:#2c3e50; color:#fff; font-family:sans-serif; }
canvas { background:#ecf0f1; border:4px solid #27ae60; border-radius:8px; }
p { font-size:18px; margin:10px 0; }
</style>
</head>
<body>
<p>🌳 森林寻宝迷宫 - 用方向键移动小精灵找宝箱!</p>
<p>步数:<span id="steps">0</span></p>
<canvas id="maze" width="300" height="300"></canvas>
<script>
// 迷宫地图:0=路 1=墙 2=起点 3=宝箱终点
const map = [
[1,1,1,1,1,1,1,1,1,1],
[1,2,0,1,0,0,0,1,0,1],
[1,1,0,1,0,1,0,0,0,1],
[1,0,0,0,0,1,1,1,0,1],
[1,0,1,1,0,0,0,0,0,1],
[1,0,1,0,0,1,1,1,0,1],
[1,0,0,0,1,0,0,0,0,1],
[1,1,1,0,1,0,1,1,0,1],
[1,0,0,0,0,0,0,1,3,1],
[1,1,1,1,1,1,1,1,1,1]
];
const canvas = document.getElementById('maze');
const ctx = canvas.getContext('2d');
const size = 30; // 每格像素
let player = {x:1, y:1}; // 角色初始位置
let steps = 0;
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for(let y=0; y<map.length; y++) {
for(let x=0; x<map[y].length; x++) {
if(map[y][x] === 1) { ctx.fillStyle='#7f8c8d'; c