js实现牧羊犬游戏代码

代码语言:html

所属分类:其他

代码由gemini-4-hydrogen ai生成,可能有错误,仅供参考:点击查看提示词

代码描述:js实现牧羊犬游戏代码

代码标签: js 牧羊犬 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>牧羊犬大作战:赶羊回圈</title>
<style>
  * { box-sizing: border-box; margin: 0; padding: 0; user-select: none; -webkit-user-select: none; }
  html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: #1b2a19;
    font-family: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, sans-serif;
    display: flex; align-items: center; justify-content: center;
    color: #2c2416;
  }
  #viewport {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
  }
  #stage {
    position: relative;
    width: 960px; height: 600px;
    flex-shrink: 0;
    transform-origin: center center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
    border-radius: 10px;
    overflow: hidden;
    background: #5f9a41;
    touch-action: none;
  }
  #gameCanvas {
    display: block;
    width: 960px; height: 600px;
    touch-action: none;
  }

  /* 顶部 HUD */
  #hud {
    position: absolute; top: 0; left: 0; width: 960px; height: 58px;
    background: linear-gradient(180deg, rgba(46, 33, 18, 0.94), rgba(62, 45, 25, 0.92));
    border-bottom: 3px solid #8c6239;
    display: none; align-items: center; justify-content: space-between;
    padding: 0 14px; color: #fdf6e3; z-index: 10;
  }
  .hud-group { display: flex; align-items: center; gap: 10px; }
  .hud-pill {
    background: rgba(255, 248, 225, 0.12);
    border: 1px solid rgba(255, 224, 160, 0.28);
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
  }
  .progress-wrap {
    width: 118px; height: 12px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.2);
  }
  .progress-bar {
    height: 100%; width: 0%;
    background: linear-gradient(90deg, #84cc16, #22c55e);
    transition: width 0.2s ease;
  }
  .timer-pill { min-width: 92px; text-align: center; font-variant-numeric: tabular-nums; }
  .timer-pill.danger {
    background: rgba(220, 38, 38, 0.35);
    border-color: #f87171;
    color: #fecaca;
    animation: pulseWarn 0.7s infinite alternate;
  }
  @keyframes pulseWarn { from { transform: scale(1); } to { transform: scale(1.04); } }

  .hud-btn {
    position: relative;
    overflow: hidden;
    background: #7c532c;
    border: 1.5px solid #c59b6d;
    color: #fff8e7;
    border-radius: 8px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
  }
  .hud-btn:hover { background: #936437; }
  .hud-btn.active { background: #2563eb; border-color: #93c5fd; }
  .hud-btn .cd-mask {
    position: absolute; left: 0; top: 0; bottom: 0; width: 0%;
    background: rgba(0, 0, 0, 0.5);
    pointer-events: none;
  }
  .hud-btn span { position: relative; z-index: 1; }

  /* 底部策略提示条 */
  #tip-banner {
    position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
    background: rgba(34, 25, 14, 0.84);
    border: 1.5px solid rgba(235, 198, 130, 0.45);
    color: #fef3c7;
    padding: 6px 16px;
    border-radius: 999px;
    font-size: 12.5px;
    max-width: 720px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    display: none;
    z-index: 9;
  }

  /* 触屏/鼠标快捷控制按钮(左下 & 右下) */
  #touch-controls {
    position: absolute; bottom: 14px; right: 16px;
    display: none; gap: 10px; z-index: 11;
  }
  .action-fab {
    width: 66px; height: 66px; border-radius: 50%;
    border: 2.5px solid #fde68a;
    background: rgba(62, 43, 21, 0.86);
    color: #fffbeb;
    font-size: 12px; font-weight: 800;
    cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    box-shadow: 0 6px 14px rgba(0,0,0,0.35);
    position: relative; overflow: hidden;
  }
  .action-fab small { font-size: 10px; opacity: 0.85; font-weight: 600; }
  .action-fab.active { background: rgba(37, 99, 235, 0.9); border-color: #bfdbfe; }
  .action-fab .fab-cd {
    position: absolute; left: 0; right: 0; bottom: 0; height: 0%;
    background: rgba(0,0,0,0.55); pointer-events: none;
  }

  /* 引导浮层(第1关提示) */
  #onboard-pill {
    position: absolute; top: 68px; left: 50%; transform: translateX(-50%);
    background: rgba(254, 249, 195, 0.94);
    border: 2px solid #d97706;
    color: #451a03;
    padding: 6px 16px;
    border-radius: 10px;
    font-size: 13px; font-weight: 700;
    pointer-events: none;
    display: none;
    z-index: 9;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  }

  /* 通用覆盖界面 */
  .screen {
    position: absolute; inset: 0;
    background: rgba(26, 38, 22, 0.72);
    backdrop-filter: blur(3px);
    display: none; align-items: center; justify-content: center;
    z-index: 20;
    padding: 20px;
  }
  .screen.active { display: flex; }

  .card {
    background: linear-gradient(180deg, #fffdf5, #f7eed6);
    border: 4px solid #7c532c;
    border-radius: 18px;
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.48), inset 0 0 0 2px #e5d2aa;
    padding: 26px 32px;
    max-width: 680px;
    width: 100%;
    text-align: center;
    color: #3b2814;
  }
  .card h1 { font-size: 34px; color: #3f6212; margin-bottom: 8px; letter-spacing: 1px; }
  .card h2 { font-size: 26px; color: #5c3d1e; margin-bottom: 10px; }
  .card p.subtitle { font-size: 14px; color: #6b5134; line-height: 1.6; margin-bottom: 18px; }

  .btn-row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }
  .btn {
    border: 2px solid #5c3a1a;
    background: linear-gradient(180deg, #84cc16, #4d7c0f);
    color: #ffffff;
    font-size: 15px; font-weight: 800;
    padding: 10px 24px;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 0 #365314;
    transition: transform 0.08s;
  }
  .btn:hover { filter: brightness(1.06); }
  .btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #365314; }
  .btn-secondary {
    background: linear-gradient(180deg, #d99b52, #a16227);
    box-shadow: 0 4px 0 #6c3e12;
  }
  .btn-secondary:active { box-shadow: 0 2px 0 #6c3e12; }
  .btn-danger {
    background: linear-gradient(180deg, #ef4444, #b91c1c);
    box-shadow: 0 4px 0 #7f1d1d;
  }

  /* 关卡网格 */
  .level-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin: 14px 0 8px;
  }
  .lvl-card {
    background: #fff9e8;
    border: 2.5px solid #b0895a;
    border-radius: 12px;
    padding: 10px 8px;
    cursor: pointer;
    transition: transform 0.12s, border-color 0.12s;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
  }
  .lvl-card:hover:not(.locked) { transform: translateY(-2px); border-color: #4d7c0f; background: #f7fee7; }
  .lvl-card.locked { background: #e7dfd0; border-color: #b7ad9c; color: #8c8273; cursor: not-allowed; opacity: 0.82; }
  .lvl-num { font-size: 15px; font-weight: 800; }
  .lvl-name { font-size: 12px; color: #6e5538; }
  .lvl-meta { font-size: 11px; color: #7c674c; }
  .lvl-stars { font-size: 15px; color: #f59e0b; letter-spacing: 2px; }
  .lvl-card.locked .lvl-stars { color: #9ca3af; }

  .help-box {
    text-align: left;
    background: rgba(140, 98, 57, 0.1);
    border: 1.5px solid rgba(140, 98, 57, 0.25);
    border-radius: 12px;
    padding: 14px 18px;
    font-size: 13.5px;
    line-height: 1.75;
    margin: 12px 0;
  }
  .kbd {
    display: inline-block; background: #fff; border: 1.5px solid #9c7a54;
    border-radius: 5px; padding: 0 6px; font-weight: 800; font-size: 12px; color: #5c3d1e;
  }
  .stars-big { font-size: 40px; color: #f59e0b; letter-spacing: 8px; margin: 8px 0; text-shadow: 0 2px 0 #b45309; }
</style>
</head>
<body>
<div id="viewport">
  <div id="stage">
    <canvas id="gameCanvas"></canvas>

    <!-- HUD -->
    <div id="hud">
      <div class="hud-group">
        <div class="hud-pill" id="hud-level">第 1 关</div>
        <div class="hud-pill" id="hud-count">入圈: 0 / 3</div>
        <div class="progress-wrap"><div class="progress-bar" id="hud-progress"></div></div>
      </div>

      <div class="hud-group">
        <div class="hud-pill timer-pill" id="hud-timer">00:55</div>
      </div>

      <div class="hud-group">
        <button class="hud-btn" id="btn-hud-sneak" title="Shift 潜行"><span>潜行 [Shift]</span></button>
        <button class="hud-btn" id="btn-hud-bark" title="空格 吠叫">
          <div class="cd-mask" id="hud-bark-cd"></div>
          <span id="hud-bark-txt">吠叫 [空格]</span>
        </button>
        <button class="hud-btn" id="btn-hud-mute" title="开关音效"><span>🔊 音效</span></button>
        <button class=.........完整代码请登录后点击上方下载按钮下载查看

网友评论0