扭伤脚踝小游戏,脚踝扭伤模拟小游戏

扭伤脚踝小游戏

扭伤脚踝小游戏

这是为您生成的一个“扭伤脚踝”主题的模拟小游戏HTML代码,它通过点击和方向键,让您体验脚踝受伤后的行动不便与康复过程。

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">扭伤脚踝 · 小游戏</title>
  <style>
    * {
      box-sizing: border-box;
      user-select: none;
    }
    body {
      background: linear-gradient(145deg, #2b3e4f 0%, #1b2a36 100%);
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      font-family: 'Segoe UI', Roboto, system-ui, sans-serif;
      margin: 0;
      padding: 16px;
    }
    .game-container {
      background: #f0e9e0;
      background-image: radial-gradient(circle at 20% 30%, #ffffff30 0%, transparent 30%);
      border-radius: 56px 56px 40px 40px;
      padding: 28px 32px 36px 32px;
      box-shadow: 0 25px 35px rgba(0, 0, 0, 0.6), inset 2px 2px 8px #ffffffb0, inset -4px -4px 12px #a08e7c;
      max-width: 780px;
      width: fit-content;
      margin: 0 auto;
      transition: all 0.1s ease;
    }
    h1 {
      text-align: center;
      margin: 0 0 10px 0;
      font-size: 2.1rem;
      font-weight: 700;
      letter-spacing: 2px;
      color: #3b2e24;
      text-shadow: 2px 2px 0 #d9c6b0, 5px 5px 0 rgba(0, 0, 0, 0.08);
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 12px;
    }
    h1 span {
      font-size: 2.5rem;
      filter: drop-shadow(2px 4px 4px rgba(0, 0, 0, 0.25));
    }
    .status-panel {
      display: flex;
      justify-content: space-between;
      align-items: center;
      background: #d9cdbc;
      border-radius: 100px;
      padding: 12px 28px;
      margin-bottom: 18px;
      box-shadow: inset 0 5px 8px #b9a89a, inset 0 -3px 5px #efe4d8, 0 6px 8px #0000001a;
      font-weight: 600;
    }
    .pain-meter {
      display: flex;
      align-items: center;
      gap: 12px;
    }
    .pain-label {
      font-size: 1rem;
      color: #4e3e32;
      letter-spacing: 0.5px;
      background: #f3ede5;
      padding: 4px 12px;
      border-radius: 50px;
      box-shadow: inset 0 0 4px #b4a18e;
    }
    .pain-bar-bg {
      width: 180px;
      height: 22px;
      background: #b09a87;
      border-radius: 40px;
      box-shadow: inset 0 4px 6px #5b4a3c, 0 1px 2px #ebddcf;
      overflow: hidden;
    }
    .pain-bar-fill {
      width: 0%;
      height: 100%;
      background: linear-gradient(90deg, #f7d44a, #f5a338, #e85d3a, #c92a2a);
      border-radius: 40px;
      transition: width 0.2s cubic-bezier(0.2, 0.9, 0.4, 1);
      box-shadow: 0 0 12px #ff9955;
    }
    .recovery-badge {
      background: #2d5a4b;
      color: #e3f2e9;
      padding: 8px 22px;
      border-radius: 40px;
      font-size: 1.2rem;
      font-weight: 700;
      box-shadow: inset 0 -3px 0 #16352b, 0 6px 10px #00000030;
      text-shadow: 0 1px 2px black;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    .recovery-badge span {
      font-size: 1.5rem;
      line-height: 1;
    }
    .canvas-wrapper {
      display: flex;
      justify-content: center;
      margin-bottom: 12px;
      border-radius: 60px;
      box-shadow: 0 12px 15px -5px #0000004d, inset 0 0 0 2px #d6c6b6, inset 0 0 30px #cbb9a6;
      background: #b8a99a;
      padding: 8px;
      transition: box-shadow 0.2s;
    }
    canvas {
      display: block;
      width: 100%;
      height: auto;
      border-radius: 40px;
      background: #d9cfc0;
      box-shadow: inset 0 0 30px #9b8b7c;
      cursor: pointer;
    }
    .controls {
      display: flex;
      flex-wrap: wrap;
      gap: 16px;
      justify-content: center;
      margin-top: 16px;
    }
    button {
      background: #ebe0d3;
      border: none;
      padding: 14px 28px;
      border-radius: 50px;
      font-weight: 700;
      font-size: 1.2rem;
      color: #2e261f;
      box-shadow: 0 8px 0 #8e7a6a, 0 10px 15px #00000030, inset 0 -2px 4px #ffffff90;
      transition: all 0.07s ease;
      display: inline-flex;
      align-items: center;
      gap: 10px;
      cursor: pointer;
      letter-spacing: 1px;
      border: 1px solid #cdbbaa;
      flex: 0 1 auto;
    }
    button:active {
      transform: translateY(5px);
      box-shadow: 0 3px 0 #6e5d4f, 0 6px 12px #00000030, inset 0 1px 4px #ffffff;
    }
    button:disabled {
      opacity: 0.5;
      transform: translateY(4px);
      box-shadow: 0 4px 0 #6e5d4f, 0 6px 12px #00000020;
      pointer-events: none;
      filter: grayscale(0.4);
    }
    .move-keys {
      display: flex;
      gap: 10px;
      align-items: center;
      background: #d9cdbc;
      padding: 6px 12px 6px 20px;
      border-radius: 50px;
      box-shadow: inset 0 3px 6px #b9a89a, inset 0 -2px 4px #f3ede5;
    }
    .move-keys button {
      padding: 12px 20px;
      font-size: 1.6rem;
      line-height: 1;
      min-width: 64px;
      justify-content: center;
    }
    .hint {
      text-align: center;
      color: #4a3e35;
      font-weight: 600;
      margin-top: 18px;
      background: #e2d7cb;
      padding: 8px 21px;
      border-radius: 60px;
      font-size: 0.95rem;
      box-shadow: inset 0 1px 6px #b8a89a;
      letter-spacing: 0.3px;
    }
    .hint i {
      font-style: normal;
      background: #2d5a4b;
      color: #e0f0e9;
      padding: 2px 12px;
      border-radius: 30px;
      margin: 0 4px;
      font-weight: 700;
    }
    .too-much {
      animation: anklePulse 0.25s ease infinite alternate;
    }
    @keyframes anklePulse {
      from { filter: drop-shadow(0 0 2px #ff7b4a); }
      to { filter: drop-shadow(0 0 12px #ff3b2f); }
    }
  </style>
</head>
<body>
  <div class="game-container" id="gameContainer">
    <h1>
      <span>🦶</span> 扭伤脚踝 · 康复训练 <span>🦶</span>
    </h1>
    <div class="status-panel">
      <div class="pain-meter">
        <span class="pain-label">疼痛值</span>
        <div class="pain-bar-bg">
          <div class="pain-bar-fill" id="painFill" style="width: 0%"></div>
        </div>
      </div>
      <div class="recovery-badge" id="recoveryBadge">
        <span>🔄</span> <span id="recoveryCount">0</span> 步
      </div>
    </div>
    <div class="canvas-wrapper" id="canvasWrapper">
      <canvas id="ankleCanvas" width="600" height="340"></canvas>
    </div>
    <div class="controls">
      <!-- 移动方向键组 -->
      <div class="move-keys">
        <button id="moveLeft" title="向左移动 (←)">←</button>
        <button id="moveRight" title="向右移动 (→)">→</button>
      </div>
      <!-- 核心康复动作 -->
      <button id="restBtn" title="休息恢复 (R)"> 🛌 休息恢复</button>
      <button id="resetBtn" title="重新开始"> 🔄 重新开始</button>
    </div>
    <div class="hint">
      <i>← →</i> 移动脚踝 · 每走一步疼痛值↑  ·  疼痛满则扭伤加重 ·  <i>休息</i> 可降低疼痛
    </div>
  </div>
  <script>
    (function(){
      const canvas = document.getElementById('ankleCanvas');
      const ctx = canvas.getContext('2d');
      const painFill = document.getElementById('painFill');
      const recoveryCountSpan = document.getElementById('recoveryCount');
      const canvasWrapper = document.getElementById('canvasWrapper');
      // 游戏状态
      let pain = 0;                     // 0 - 100
      let steps = 0;                   // 总移动步数(成功移动次数)
      let ankleOffsetX = 0;            // 水平偏移 -100 .. 100   (影响姿态)
      let isResting = false;           // 是否正在休息动画(禁用移动)
      let restingTimer = null;         // 休息计时器
      let gameOver = false;            // 疼痛值达到100后无法移动,只能重置或休息?休息可以降低疼痛,游戏可以继续
      // 但是没有真正的失败,只是疼痛不能移动,我们不让移动,但休息可以继续。
      // 常量
      const MAX_PAIN = 100;
      const PAIN_PER_MOVE = 12;        // 每移动一次增加的疼痛
      const PAIN_REDUCE_REST = 35;     // 每次休息降低的疼痛
      const OFFSET_STEP = 25;          // 每次移动偏移变化量
      const MAX_OFFSET = 100;
      // 休息时用
      let restAnimationFrame = null;
      // DOM 元素
      const moveLeftBtn = document.getElementById('moveLeft');
      const moveRightBtn = document.getElementById('moveRight');
      const restBtn = document.getElementById('restBtn');
      const resetBtn = document.getElementById('resetBtn');
      // ----- 工具函数 -----
      function clamp(value, min, max) {
        return Math.min(max, Math.max(min, value));
      }
      // 更新UI疼痛条,以及按钮状态
      function updateUI() {
        const painPercent = (pain / MAX_PAIN) * 100;
        painFill.style.width = `${painPercent}%`;
        // 疼痛值显示颜色警告
        if (pain >= 80) {
          canvasWrapper.classList.add('too-much');
        } else {
          canvasWrapper.classList.remove('too-much');
        }
        // 根据疼痛值或休息状态禁用移动按钮
        const disableMove = (pain >= MAX_PAIN) || isResting || gameOver;
        moveLeftBtn.disabled = disableMove;
        moveRightBtn.disabled = disableMove;
        // 休息按钮: 如果疼痛为0或休息中/游戏结束(其实可继续休息) 或者休息中不要再点
        // 疼痛0无需休息,休息中不能点,可以禁用,防止重复点击
        restBtn.disabled = (pain <= 0) || isResting;
        // 更新步数显示
        recoveryCountSpan.textContent = steps;
      }
      // 应用移动后的状态(增加疼痛,偏移)
      function applyMove(direction) {
        if (pain >= MAX_PAIN || isResting) return false;
        // 方向: -1 左, 1 右
        let delta = direction === 'left' ? -OFFSET_STEP : OFFSET_STEP;
        ankleOffsetX = clamp(ankleOffsetX + delta, -MAX_OFFSET, MAX_OFFSET);
        // 增加疼痛
        pain = clamp(pain + PAIN_PER_MOVE, 0, MAX_PAIN);
        // 增加步数
        steps++;
        // 如果疼痛到达100, 标记gameOver(只是无法移动, 但休息后仍可)
        if (pain >= MAX_PAIN) {
          // 只是cannot move, 不用特别设置gameOver变量,但不影响休息
        }
        updateUI();
        drawAnkle();
        return true;
      }
      // 休息逻辑
      function restAndRecover() {
        if (isResting) return;
        if (pain <= 0) return;
        // 标记休息中,禁用按钮
        isResting = true;
        updateUI();
        // 播放简单的休息动画(脚踝微微颤动)
        let startTime = performance.now();
        const restDuration = 550; // 毫秒
        function animateRest(now) {
          const elapsed = now - startTime;
          const progress = Math.min(elapsed / restDuration, 1);
          // 绘制一个轻柔变化的脚踝 (用sin波动)
          drawAnkle(progress);
          if (progress < 1) {
            restAnimationFrame = requestAnimationFrame(animateRest);
          } else {
            // 休息结束
            isResting = false;
            // 降低疼痛
            pain = clamp(pain - PAIN_REDUCE_REST, 0, MAX_PAIN);
            // 稍微回正一点脚踝偏移
            ankleOffsetX = clamp(ankleOffsetX * 0.5, -MAX_OFFSET, MAX_OFFSET);
            updateUI();
            drawAnkle();
            restAnimationFrame = null;
          }
        }
        restAnimationFrame = requestAnimationFrame(animateRest);
      }
      // 重置游戏
      function resetGame() {
        // 取消任何进行中的休息动画
        if (restAnimationFrame) {
          cancelAnimationFrame(restAnimationFrame);
          restAnimationFrame = null;
        }
        if (restingTimer) {
          clearTimeout(restingTimer);
          restingTimer = null;
        }
        isResting = false;
        pain = 0;
        steps = 0;
        ankleOffsetX = 0;
        gameOver = false;
        updateUI();
        drawAnkle();
      }
      // ----- 绘制脚踝 (核心视觉效果) -----
      function drawAnkle(restProgress = 0) {
        // 清空画布
        ctx.clearRect(0, 0, canvas.width, canvas.height);
        // 背景装饰 (轻微纹理)
        ctx.fillStyle = '#d9cfc0';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        // 绘制一个软垫 / 地面
        ctx.beginPath();
        ctx.ellipse(300, 260, 260, 80, 0, 0, Math.PI * 2);
        ctx.fillStyle = '#b8a99a';
        ctx.shadowColor = '#6b5a4b';
        ctx.shadowBlur = 24;
        ctx.shadowOffsetY = 8;
        ctx.fill();
        ctx.shadowColor = 'transparent'; // reset for other drawings
        ctx.shadowBlur = 0;
        ctx.shadowOffsetY = 0;
        // 绘制脚踝的主体 —— 腿部
        const baseX = 300;
        const baseY = 190;          // 脚踝关节中心
        const offsetX = ankleOffsetX * 0.8; // 偏移视觉缩放
        // 休息时的微微颤动 (restProgress 0~1)
        let restingWobble = 0;
        if (isResting) {
          restingWobble = Math.sin(restProgress * Math.PI * 8) * 3;
        }
        // 脚踝关节坐标 (根据偏移移动,但不会太夸张)
        const ankleX = baseX + offsetX;
        const ankleY = baseY + (isResting ? 2 : 0) + (restingWobble * 0.5);
        // ----- 绘制小腿 (从膝盖到脚踝)-----
        ctx.save();
        // 腿部稍微倾斜,根据偏移,制造扭伤感
        const kneeX = 360 + offsetX * 0.5;  // 膝盖位置
        const kneeY = 70;
        // 小腿路径 (贝塞尔曲线)
        ctx.beginPath();
        ctx.moveTo(kneeX - 40, kneeY);
        ctx.quadraticCurveTo(ankleX - 30, ankleY - 40, ankleX - 18, ankleY + 5);
        ctx.lineTo(ankleX + 22, ankleY + 8);
        ctx.quadraticCurveTo(kneeX + 48, kneeY + 20, kneeX + 30, kneeY);
        ctx.closePath();
        // 腿部渐变填充
        const legGrad = ctx.createLinearGradient(kneeX - 30, kneeY, ankleX, ankleY + 30);
        legGrad.addColorStop(0, '#f2d1b0');
        legGrad.addColorStop(0.7, '#dcb594');
        legGrad.addColorStop(1, '#c49a7a');
        ctx.fillStyle = legGrad;
        ctx.shadowColor = '#8a6e5a';
        ctx.shadowBlur = 12;
        ctx.shadowOffsetX = 2;
        ctx.shadowOffsetY = 4;
        ctx.fill();
        ctx.shadowColor = 'transparent';
        ctx.shadowBlur = 0;
        // 膝盖装饰
        ctx.beginPath();
        ctx.ellipse(kneeX - 4, kneeY - 6, 18, 12, 0.1, 0, Math.PI * 2);
        ctx.fillStyle = '#e6c7ab';
        ctx.fill();
        // ----- 绘制脚掌 (踝关节下方) -----
        // 脚掌方向与偏移有关,扭转感
        const footAngle = offsetX * 0.008; // 轻微旋转
        ctx.save();
        ctx.translate(ankleX, ankleY + 12);
        ctx.rotate(footAngle);
        // 脚掌 (椭圆形)
        ctx.beginPath();
        ctx.ellipse(0, 18, 55, 28, 0, 0, Math.PI * 2);
        const footGrad = ctx.createRadialGradient(-10, 25, 5, 10, 30, 50);
        footGrad.addColorStop(0, '#ebc7aa');
        footGrad.addColorStop(0.7, '#d4a987');
        footGrad.addColorStop(1, '#b2815e');
        ctx.fillStyle = footGrad;
        ctx.shadowColor = '#735a48';
        ctx.shadowBlur = 16;
        ctx.shadowOffsetY = 6;
        ctx.fill();
        // 脚趾提示
        ctx.beginPath();
        ctx.ellipse(-45, 25, 12, 8, -0.2, 0, Math.PI * 2);
        ctx.fillStyle = '#e6c1a2';
        ctx.fill();
        ctx.beginPath();
        ctx.ellipse(45, 30, 10, 7, 0.2, 0, Math.PI * 2);
        ctx.fillStyle = '#e6c1a2';
        ctx.fill();
        ctx.restore(); // restore foot rotation
        // 绘制脚踝关节(圆润,肿胀感随疼痛增加)
        ctx.beginPath();
        const swelling = 6 + (pain / 100) * 18; // 疼痛越高越肿
        ctx.ellipse(ankleX, ankleY - 4, 26 + swelling * 0.5, 20 + swelling * 0.4, 0.1, 0, Math.PI * 2);
        const jointGrad = ctx.createRadialGradient(ankleX - 10, ankleY - 10, 5, ankleX + 8, ankleY + 5, 35);
        jointGrad.addColorStop(0, '#f5ddc4');
        jointGrad.addColorStop(0.6, '#e8c3a2');
        jointGrad.addColorStop(1, '#c49672');
        ctx.fillStyle = jointGrad;
        ctx.shadowColor = '#6b4f3c';
        ctx.shadowBlur = 15;
        ctx.shadowOffsetY = 4;
        ctx.fill();
        // 疼痛时脚踝处加上红晕
        if (pain > 30) {
          ctx.beginPath();
          ctx.ellipse(ankleX, ankleY - 4, 28 + swelling * 0.5, 22 + swelling * 0.3, 0.1, 0, Math.PI * 2);
          ctx.fillStyle = `rgba(220, 70, 30, ${Math.min(0.45, pain / 300)})`;
          ctx.fill();
        }
        // 脚踝表面高光
        ctx.beginPath();
        ctx.ellipse(ankleX - 8, ankleY - 12, 10, 8, 0.2, 0, Math.PI * 2);
        ctx.fillStyle = '#fff6e8b0';
        ctx.fill();
        // 绘制一些类似护具/绷带的线条(增加趣味,疼痛高的时候绷带明显)
        if (pain > 30) {
          ctx.save();
          ctx.strokeStyle = '#e0d6cc';
          ctx.lineWidth = 4;
          ctx.shadowBlur = 6;
          ctx.shadowColor = '#aaa';
          ctx.beginPath();
          ctx.ellipse(ankleX - 6, ankleY - 1, 22, 16, 0.1, 0, Math.PI * 2);
          ctx.strokeStyle = `rgba(230, 210, 190, ${pain / 150})`;
          ctx.stroke();
          ctx.beginPath();
          ctx.ellipse(ankleX + 4, ankleY + 2, 20, 14, -0.1, 0, Math.PI * 2);
          ctx.stroke();
          ctx.restore();
        }
        // 绘制疼痛值表情 (可选)
        if (pain > 70) {
          ctx.font = 'bold 30px "Segoe UI", sans-serif';
          ctx.fillStyle = '#d43f1f';
          ctx.shadowColor = '#3f1f0f';
          ctx.shadowBlur = 8;
          ctx.shadowOffsetY = 2;
          ctx.fillText('😖', 480, 100);
        } else if (pain > 40) {
          ctx.font = 'bold 30px "Segoe UI", sans-serif';
          ctx.fillStyle = '#b8862e';
          ctx.shadowColor = '#3f1f0f';
          ctx.shadowBlur = 8;
          ctx.fillText('😣', 480, 100);
        } else if (pain > 0) {
          ctx.font = 'bold 30px "Segoe UI", sans-serif';
          ctx.fillStyle = '#3e7a5e';
          ctx.shadowColor = '#1a3328';
          ctx.shadowBlur = 8;
          ctx.fillText('😉', 480, 100);
        } else {
          ctx.font = 'bold 30px "Segoe UI", sans-serif';
          ctx.fillStyle = '#2d6b4b';
          ctx.shadowColor = '#0f2e21';
          ctx.shadowBlur = 8;
          ctx.fillText('😌', 480, 100);
        }
        ctx.shadowColor = 'transparent'; // reset
        // 绘制偏移指示箭头 (视觉反馈)
        if (ankleOffsetX < -12) {
          ctx.font = 'bold 24px "Segoe UI"';
          ctx.fillStyle = '#a14b2b';
          ctx.fillText('⟵', 100, 100);
        } else if (ankleOffsetX > 12) {
          ctx.font = 'bold 24px "Segoe UI"';
          ctx.fillStyle = '#a14b2b';
          ctx.fillText('⟶', 470, 100);
        }
        // 如果正在休息,绘制“休息中”文字
        if (isResting) {
          ctx.font = 'bold 24px "Segoe UI", sans-serif';
          ctx.fillStyle = '#1f5e4c';
          ctx.shadowColor = '#c0d6cc';
          ctx.shadowBlur = 12;
          ctx.shadowOffsetY = 2;
          ctx.fillText('🛌 休息中...', 210, 90);
          ctx.shadowColor = 'transparent';
        }
      }
      // ----- 事件监听 -----
      function handleLeft() {
        if (applyMove('left')) {
          // 移动后可能疼痛满了,按钮会禁用
        }
      }
      function handleRight() {
        if (applyMove('right')) {
          // 同上
        }
      }
      // 键盘支持
      function handleKeyDown(e) {
        const key = e.key;
        // 阻止箭头滚动
        if (key === 'ArrowLeft' || key === 'ArrowRight' || key === 'r' || key === 'R') {
          e.preventDefault();
        }
        if (key === 'ArrowLeft') {
          if (!moveLeftBtn.disabled) handleLeft();
        } else if (key === 'ArrowRight') {
          if (!moveRightBtn.disabled) handleRight();
        } else if (key === 'r' || key === 'R') {
          if (!restBtn.disabled) restAndRecover();
        } else if (key === 'Escape') {
          resetGame();
        }
      }
      // 初始化
      function init() {
        // 绘制初始状态
        resetGame();
        // 按钮事件
        moveLeftBtn.addEventListener('click', handleLeft);
        moveRightBtn.addEventListener('click', handleRight);
        restBtn.addEventListener('click', restAndRecover);
        resetBtn.addEventListener('click', resetGame);
        window.addEventListener('keydown', handleKeyDown);
        // 画布点击也可以作为额外引导 (但不需要)
        // 防止鼠标点击canvas误触
      }
      init();
    })();
  </script>
</body>
</html>

游戏机制与视觉反馈

游戏的核心是让您通过操作来感受脚踝扭伤后行动与恢复的平衡,您可以通过以下方式与游戏互动:

  • 移动与疼痛:点击 或 按钮(或使用键盘方向键)可以让脚踝向左或向右移动,但每次移动都会增加“疼痛值”,疼痛值会实时显示在顶部的进度条中。
  • 休息与恢复:当疼痛值积累起来后,可以点击 “休息恢复” 按钮,脚踝会进入短暂的休息动画,随后疼痛值会明显下降。
  • 视觉反馈:脚踝的肿胀程度、表情符号以及画布边框的脉冲效果都会随着疼痛值的变化而改变,让您直观地感受到状态的变化,疼痛值过高时,移动按钮将被禁用,迫使您进行休息。

扭伤脚踝小游戏

发表评论