返回列表 发布新帖

围住小猫改进版游戏,橘猫、虎斑、狸花猫,根据小猫性格改良的一款小游戏

3125 0
小K网牛逼 发表于 2026-6-23 00:00:19 | 查看全部 阅读模式 <

马上注册,结交更多好友,享用更多功能,让你轻松玩转小K网。

您需要 登录 才可以下载或查看,没有账号?立即注册 微信登录

×

围住小猫改进版游戏,橘猫、虎斑、狸花猫,根据小猫性格改良的一款小游戏 ... ...

围住小猫改进版游戏,橘猫、虎斑、狸花猫,根据小猫性格改良的一款小游戏

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
  6.     <title>围住小猫-By Mr yang</title>
  7.     <style>
  8.         * {
  9.             margin: 0;
  10.             padding: 0;
  11.             box-sizing: border-box;
  12.         }
  13.          
  14.         body {
  15.             font-family: "Microsoft YaHei", "PingFang SC", -apple-system, sans-serif;
  16.             min-height: 100vh;
  17.             background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  18.             display: flex;
  19.             flex-direction: column;
  20.             align-items: center;
  21.             overflow-x: hidden;
  22.         }
  23.          
  24.         /* 页面容器 */
  25.         .page {
  26.             display: none;
  27.             width: 100%;
  28.             max-width: 100%;
  29.             padding: 20px;
  30.             animation: fadeIn 0.3s ease;
  31.         }
  32.          
  33.         .page.active {
  34.             display: block;
  35.         }
  36.          
  37.         @keyframes fadeIn {
  38.             from { opacity: 0; transform: translateY(10px); }
  39.             to { opacity: 1; transform: translateY(0); }
  40.         }
  41.          
  42.         /* ========== 选择页面 ========== */
  43.         .select-title {
  44.             font-size: 36px;
  45.             color: white;
  46.             text-shadow: 3px 3px 6px rgba(0,0,0,0.3);
  47.             margin: 30px 0 20px;
  48.             text-align: center;
  49.             font-weight: bold;
  50.         }
  51.          
  52.         .select-subtitle {
  53.             color: rgba(255,255,255,0.9);
  54.             font-size: 16px;
  55.             text-align: center;
  56.             margin-bottom: 30px;
  57.         }
  58.          
  59.         /* 猫咪卡片 */
  60.         .cat-cards {
  61.             display: flex;
  62.             flex-direction: column;
  63.             gap: 20px;
  64.             width: 100%;
  65.             max-width: 400px;
  66.             margin: 0 auto;
  67.         }
  68.          
  69.         .cat-card {
  70.             background: rgba(255, 255, 255, 0.95);
  71.             border-radius: 20px;
  72.             padding: 20px;
  73.             display: flex;
  74.             align-items: center;
  75.             gap: 20px;
  76.             cursor: pointer;
  77.             transition: all 0.3s ease;
  78.             box-shadow: 0 10px 30px rgba(0,0,0,0.15);
  79.             border: 3px solid transparent;
  80.         }
  81.          
  82.         .cat-card:hover {
  83.             transform: translateY(-5px);
  84.             box-shadow: 0 15px 40px rgba(0,0,0,0.25);
  85.         }
  86.          
  87.         .cat-card:active {
  88.             transform: scale(0.98);
  89.         }
  90.          
  91.         .cat-card-img {
  92.             width: 80px;
  93.             height: 80px;
  94.             border-radius: 50%;
  95.             object-fit: cover;
  96.             box-shadow: 0 4px 15px rgba(0,0,0,0.1);
  97.             flex-shrink: 0;
  98.         }
  99.          
  100.         .cat-card-info {
  101.             flex: 1;
  102.         }
  103.          
  104.         .cat-card-name {
  105.             font-size: 22px;
  106.             font-weight: bold;
  107.             color: #333;
  108.             margin-bottom: 5px;
  109.         }
  110.          
  111.         .cat-card-difficulty {
  112.             display: inline-block;
  113.             font-size: 13px;
  114.             padding: 4px 12px;
  115.             border-radius: 12px;
  116.             color: white;
  117.             margin-bottom: 8px;
  118.         }
  119.          
  120.         .diff-low { background: linear-gradient(135deg, #52c41a, #73d13d); }
  121.         .diff-medium { background: linear-gradient(135deg, #faad14, #ffc53d); }
  122.         .diff-high { background: linear-gradient(135deg, #ff4d4f, #ff7875); }
  123.          
  124.         .cat-card-desc {
  125.             font-size: 14px;
  126.             color: #666;
  127.         }
  128.          
  129.         /* ========== 游戏页面 ========== */
  130.         .game-header {
  131.             display: flex;
  132.             align-items: center;
  133.             justify-content: space-between;
  134.             width: 100%;
  135.             max-width: 500px;
  136.             margin-bottom: 15px;
  137.             padding: 0 5px;
  138.         }
  139.          
  140.         .back-btn {
  141.             background: rgba(255,255,255,0.2);
  142.             border: none;
  143.             color: white;
  144.             padding: 10px 15px;
  145.             border-radius: 20px;
  146.             font-size: 14px;
  147.             cursor: pointer;
  148.             display: flex;
  149.             align-items: center;
  150.             gap: 5px;
  151.             transition: 0.3s;
  152.         }
  153.          
  154.         .back-btn:hover {
  155.             background: rgba(255,255,255,0.3);
  156.         }
  157.          
  158.         .current-cat-badge {
  159.             background: rgba(255,255,255,0.9);
  160.             padding: 8px 16px;
  161.             border-radius: 20px;
  162.             display: flex;
  163.             align-items: center;
  164.             gap: 8px;
  165.             font-size: 14px;
  166.             color: #333;
  167.             font-weight: bold;
  168.         }
  169.          
  170.         .current-cat-badge img {
  171.             width: 24px;
  172.             height: 24px;
  173.             border-radius: 50%;
  174.             object-fit: cover;
  175.         }
  176.          
  177.         .game-container {
  178.             background: rgba(255, 255, 255, 0.98);
  179.             border-radius: 20px;
  180.             padding: 20px;
  181.             box-shadow: 0 15px 60px rgba(0,0,0,0.2);
  182.             width: 100%;
  183.             max-width: 500px;
  184.         }
  185.          
  186.         .game-status-bar {
  187.             display: flex;
  188.             justify-content: space-around;
  189.             margin-bottom: 15px;
  190.             padding: 10px;
  191.             background: #f8f9fa;
  192.             border-radius: 12px;
  193.         }
  194.          
  195.         .status-item {
  196.             display: flex;
  197.             flex-direction: column;
  198.             align-items: center;
  199.             gap: 3px;
  200.         }
  201.          
  202.         .status-item .label {
  203.             font-size: 11px;
  204.             color: #999;
  205.         }
  206.          
  207.         .status-item .value {
  208.             font-size: 15px;
  209.             font-weight: bold;
  210.             color: #333;
  211.         }
  212.          
  213.         .status-text {
  214.             text-align: center;
  215.             font-size: 16px;
  216.             color: #667eea;
  217.             font-weight: bold;
  218.             margin-bottom: 10px;
  219.             min-height: 24px;
  220.         }
  221.          
  222.         .status-text.win { color: #52c41a; }
  223.         .status-text.lose { color: #ff4d4f; }
  224.          
  225.         .restart-hint {
  226.             text-align: center;
  227.             font-size: 13px;
  228.             color: #999;
  229.             margin-bottom: 10px;
  230.             opacity: 0;
  231.             transition: 0.3s;
  232.         }
  233.          
  234.         .restart-hint.show { opacity: 1; }
  235.          
  236.         /* Canvas容器 */
  237.         .canvas-wrapper {
  238.             display: flex;
  239.             justify-content: center;
  240.             padding: 10px;
  241.             background: linear-gradient(135deg, #667eea22, #764ba222);
  242.             border-radius: 15px;
  243.             overflow-x: auto;
  244.             -webkit-overflow-scrolling: touch;
  245.         }
  246.          
  247.         canvas {
  248.             display: block;
  249.             cursor: pointer;
  250.             max-width: 100%;
  251.             height: auto;
  252.             -webkit-tap-highlight-color: transparent;
  253.             -webkit-touch-callout: none;
  254.             -webkit-user-select: none;
  255.             user-select: none;
  256.             outline: none;
  257.         }
  258.          
  259.         /* 难度说明 */
  260.         .difficulty-card {
  261.             margin-top: 15px;
  262.             padding: 15px;
  263.             background: #f8f9fa;
  264.             border-radius: 12px;
  265.         }
  266.          
  267.         .difficulty-card h3 {
  268.             font-size: 14px;
  269.             color: #333;
  270.             margin-bottom: 10px;
  271.             text-align: center;
  272.         }
  273.          
  274.         .difficulty-list {
  275.             display: flex;
  276.             flex-direction: column;
  277.             gap: 6px;
  278.         }
  279.          
  280.         .difficulty-item {
  281.             display: flex;
  282.             align-items: center;
  283.             gap: 8px;
  284.             font-size: 12px;
  285.             color: #555;
  286.         }
  287.          
  288.         .difficulty-item .emoji {
  289.             font-size: 16px;
  290.         }
  291.          
  292.         /* 重新开始按钮 */
  293.         .restart-btn {
  294.             width: 100%;
  295.             margin-top: 15px;
  296.             padding: 14px;
  297.             background: linear-gradient(135deg, #667eea, #764ba2);
  298.             color: white;
  299.             border: none;
  300.             border-radius: 25px;
  301.             font-size: 16px;
  302.             font-weight: bold;
  303.             cursor: pointer;
  304.             transition: all 0.3s;
  305.             box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
  306.         }
  307.          
  308.         .restart-btn:hover {
  309.             transform: translateY(-2px);
  310.             box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
  311.         }
  312.          
  313.         .restart-btn:active {
  314.             transform: scale(0.98);
  315.         }
  316.          
  317.         /* ========== 响应式适配 ========== */
  318.         [url=home.php?mod=space&uid=945662]@media[/url] (max-width: 480px) {
  319.             .select-title {
  320.                 font-size: 28px;
  321.                 margin: 20px 0 15px;
  322.             }
  323.             
  324.             .select-subtitle {
  325.                 font-size: 14px;
  326.                 margin-bottom: 20px;
  327.             }
  328.             
  329.             .cat-cards {
  330.                 padding: 0 10px;
  331.             }
  332.             
  333.             .cat-card {
  334.                 padding: 15px;
  335.                 gap: 15px;
  336.             }
  337.             
  338.             .cat-card-img {
  339.                 width: 65px;
  340.                 height: 65px;
  341.             }
  342.             
  343.             .cat-card-name {
  344.                 font-size: 18px;
  345.             }
  346.             
  347.             .cat-card-desc {
  348.                 font-size: 13px;
  349.             }
  350.             
  351.             .game-container {
  352.                 padding: 15px;
  353.                 border-radius: 15px;
  354.             }
  355.             
  356.             .game-status-bar {
  357.                 padding: 8px;
  358.             }
  359.             
  360.             .status-item .label {
  361.                 font-size: 10px;
  362.             }
  363.             
  364.             .status-item .value {
  365.                 font-size: 13px;
  366.             }
  367.             
  368.             .difficulty-card {
  369.                 padding: 12px;
  370.             }
  371.             
  372.             .difficulty-item {
  373.                 font-size: 11px;
  374.             }
  375.         }
  376.          
  377.         /* 横屏适配 */
  378.         @media (max-height: 500px) and (orientation: landscape) {
  379.             .select-title {
  380.                 font-size: 24px;
  381.                 margin: 10px 0;
  382.             }
  383.             
  384.             .select-subtitle {
  385.                 display: none;
  386.             }
  387.             
  388.             .cat-cards {
  389.                 flex-direction: row;
  390.                 max-width: 100%;
  391.                 overflow-x: auto;
  392.                 gap: 15px;
  393.                 padding: 0 10px;
  394.             }
  395.             
  396.             .cat-card {
  397.                 flex-direction: column;
  398.                 min-width: 140px;
  399.                 padding: 15px;
  400.                 text-align: center;
  401.             }
  402.             
  403.             .cat-card-info {
  404.                 display: flex;
  405.                 flex-direction: column;
  406.                 align-items: center;
  407.             }
  408.         }
  409.     </style>
  410. </head>
  411. <body>
  412.     <!-- ========== 选择猫咪页面 ========== -->
  413.     <div id="selectPage" class="page active">
  414.         <h1 class="select-title">围住小猫</h1>
  415.         <p class="select-subtitle">摸鱼摸鱼&#128031;&#65039;,打发时间....</p>
  416.          
  417.         <div class="cat-cards">
  418.             <div class="cat-card" onclick="startGame('orange')">
  419.                 <img class="cat-card-img" src="https://coze-coding-project.tos.coze.site/coze_storage_7633745811309953058/image/generate_image_fef41237-3294-4d26-961f-da549e688db7.jpeg?sign=1808906758-1f5b482dea-0-b5fb3a750ad553b048f383d5032514900fa9ff36037ca2705e1bedc1eb87270a" alt="橘猫">
  420.                 <div class="cat-card-info">
  421.                     <div class="cat-card-name">橘猫</div>
  422.                     <span class="cat-card-difficulty diff-low">佛系</span>
  423.                     <div class="cat-card-desc">走一步,慢悠悠的~</div>
  424.                 </div>
  425.             </div>
  426.             
  427.             <div class="cat-card" onclick="startGame('tabby')">
  428.                 <img class="cat-card-img" src="https://coze-coding-project.tos.coze.site/coze_storage_7633745811309953058/image/generate_image_8fb2213f-8103-42db-ba18-5bacd5706749.jpeg?sign=1808906764-896eafba5d-0-8860c0eeb05efbbac4f103af0705d2a00434a32ba05358426e074f93627c6e7c" alt="虎斑猫">
  429.                 <div class="cat-card-info">
  430.                     <div class="cat-card-name">虎斑猫</div>
  431.                     <span class="cat-card-difficulty diff-medium">敏捷</span>
  432.                     <div class="cat-card-desc">走一步,速度更快~</div>
  433.                 </div>
  434.             </div>
  435.             
  436.             <div class="cat-card" onclick="startGame('lihua')">
  437.                 <img class="cat-card-img" src="https://coze-coding-project.tos.coze.site/coze_storage_7633745811309953058/image/generate_image_2f4ca293-4b47-4254-9506-62759412fdcc.jpeg?sign=1808906761-46b3d7c170-0-ec10d13ced249bf5ff258ba5e164669c538f5a0c33d84f9fe18f0302e7e14b6a" alt="狸花猫">
  438.                 <div class="cat-card-info">
  439.                     <div class="cat-card-name">狸花猫</div>
  440.                     <span class="cat-card-difficulty diff-high">狡猾</span>
  441.                     <div class="cat-card-desc">走两步,心眼超多~</div>
  442.                 </div>
  443.             </div>
  444.         </div>
  445.     </div>
  446.    
  447.     <!-- ========== 游戏页面 ========== -->
  448.     <div id="gamePage" class="page">
  449.         <div class="game-header">
  450.             <button class="back-btn" onclick="goBack()">
  451.                 <span><</span> 返回
  452.             </button>
  453.             <div class="current-cat-badge" id="currentCatBadge">
  454.                 <img id="badgeCatImg" src="" alt="">
  455.                 <span id="badgeCatName">橘猫</span>
  456.             </div>
  457.         </div>
  458.          
  459.         <div class="game-container">
  460.             <div class="game-status-bar">
  461.                 <div class="status-item">
  462.                     <span class="label">放置次数</span>
  463.                     <span class="value" id="moveCount">0</span>
  464.                 </div>
  465.                 <div class="status-item">
  466.                     <span class="label">限制</span>
  467.                     <span class="value">≤13步</span>
  468.                 </div>
  469.                 <div class="status-item">
  470.                     <span class="label">难度</span>
  471.                     <span class="value" id="difficultyText">佛系</span>
  472.                 </div>
  473.                 <div class="status-item">
  474.                     <span class="label">猫咪位置</span>
  475.                     <span class="value" id="catPosition">(5,5)</span>
  476.                 </div>
  477.             </div>
  478.             
  479.             <div id="status" class="status-text">点击蓝色圆点开始围堵</div>
  480.             <div id="restartHint" class="restart-hint">点击重新开始</div>
  481.             
  482.             <div class="canvas-wrapper">
  483.                 <canvas id="catCanvas"></canvas>
  484.             </div>
  485.             
  486.             <div class="difficulty-card">
  487.                 <h3>游戏说明</h3>
  488.                 <div class="difficulty-list">
  489.                     <div class="difficulty-item">
  490.                         <span class="emoji">&#128049;</span>
  491.                         <span>点击蓝色圆点放置障碍物</span>
  492.                     </div>
  493.                     <div class="difficulty-item">
  494.                         <span class="emoji">&#127919;</span>
  495.                         <span>围住猫咪 + ≤13步 = 胜利</span>
  496.                     </div>
  497.                     <div class="difficulty-item">
  498.                         <span class="emoji" id="hintEmoji">&#128049;</span>
  499.                         <span id="hintText">橘猫每次走一步</span>
  500.                     </div>
  501.                     <div class="difficulty-item" id="lihuaHint" style="display:none;">
  502.                         <span class="emoji">&#9888;&#65039;</span>
  503.                         <span>围堵太紧时狸花猫会愤怒跳两步!</span>
  504.                     </div>
  505.                 </div>
  506.             </div>
  507.             
  508.             <button class="restart-btn" onclick="restartGame()">重新开始</button>
  509.         </div>
  510.     </div>
  511.    
  512.     <script>
  513.         const canvas = document.getElementById('catCanvas');
  514.         const ctx = canvas.getContext('2d');
  515.         const statusText = document.getElementById('status');
  516.         const restartHint = document.getElementById('restartHint');
  517.         const moveCountDisplay = document.getElementById('moveCount');
  518.         const catPositionDisplay = document.getElementById('catPosition');
  519.         const difficultyText = document.getElementById('difficultyText');
  520.         const hintText = document.getElementById('hintText');
  521.         const hintEmoji = document.getElementById('hintEmoji');
  522.         const badgeCatImg = document.getElementById('badgeCatImg');
  523.         const badgeCatName = document.getElementById('badgeCatName');
  524.    
  525.         // 游戏配置
  526.         const ROWS = 11, COLS = 11, RADIUS = 16, GAP = 6;
  527.          
  528.         // 响应式调整画布大小
  529.         function resizeCanvas() {
  530.             const screenWidth = window.innerWidth;
  531.             let canvasWidth, canvasHeight;
  532.             
  533.             if (screenWidth <= 480) {
  534.                 // 手机端:缩小圆点和间距
  535.                 canvas.width = COLS * (RADIUS * 2 + GAP) + RADIUS + 10;
  536.                 canvas.height = ROWS * (RADIUS * 2 + 4) + 10;
  537.             } else {
  538.                 // 桌面端
  539.                 canvas.width = COLS * (RADIUS * 2 + GAP) + RADIUS + 15;
  540.                 canvas.height = ROWS * (RADIUS * 2 + 4) + 15;
  541.             }
  542.         }
  543.          
  544.         // 猫咪配置
  545.         const catConfigs = {
  546.             orange: {
  547.                 name: '橘猫',
  548.                 difficulty: '佛系',
  549.                 steps: 1,
  550.                 speed: 200,
  551.                 furColor: '#FF8C00',
  552.                 bellyColor: '#FFB347',
  553.                 eyeColor: '#000',
  554.                 emoji: '&#128049;'
  555.             },
  556.             tabby: {
  557.                 name: '虎斑猫',
  558.                 difficulty: '敏捷',
  559.                 steps: 1,
  560.                 speed: 120,
  561.                 furColor: '#708090',
  562.                 bellyColor: '#C0C0C0',
  563.                 eyeColor: '#2F4F4F',
  564.                 emoji: '&#128047;'
  565.             },
  566.             lihua: {
  567.                 name: '狸花猫',
  568.                 difficulty: '狡猾',
  569.                 steps: 1,  // 默认走一步
  570.                 speed: 150,
  571.                 furColor: '#8B4513',
  572.                 bellyColor: '#DEB887',
  573.                 eyeColor: '#006400',
  574.                 emoji: '&#129418;',
  575.                 angrySteps: 2  // 被激怒时走两步
  576.             }
  577.         };
  578.          
  579.         // 猫咪图片
  580.         const catImages = {};
  581.         const catImageUrls = {
  582.             orange: 'https://coze-coding-project.tos.coze.site/coze_storage_7633745811309953058/image/generate_image_fef41237-3294-4d26-961f-da549e688db7.jpeg?sign=1808906758-1f5b482dea-0-b5fb3a750ad553b048f383d5032514900fa9ff36037ca2705e1bedc1eb87270a',
  583.             tabby: 'https://coze-coding-project.tos.coze.site/coze_storage_7633745811309953058/image/generate_image_8fb2213f-8103-42db-ba18-5bacd5706749.jpeg?sign=1808906764-896eafba5d-0-8860c0eeb05efbbac4f103af0705d2a00434a32ba05358426e074f93627c6e7c',
  584.             lihua: 'https://coze-coding-project.tos.coze.site/coze_storage_7633745811309953058/image/generate_image_2f4ca293-4b47-4254-9506-62759412fdcc.jpeg?sign=1808906761-46b3d7c170-0-ec10d13ced249bf5ff258ba5e164669c538f5a0c33d84f9fe18f0302e7e14b6a'
  585.         };
  586.          
  587.         // 游戏状态
  588.         let currentCatType = 'orange';
  589.         let moveCount = 0;
  590.         let map = [], catPos = { r: 5, c: 5 }, catDrawPos = { x: 0, y: 0 }, catDir = 1;
  591.         let isOver = false, isAnimating = false;
  592.         let aniId = null;
  593.          
  594.         // 预加载猫咪图片
  595.         function preloadCatImages() {
  596.             return new Promise((resolve) => {
  597.                 let loaded = 0;
  598.                 const total = Object.keys(catImageUrls).length;
  599.                  
  600.                 Object.keys(catImageUrls).forEach(type => {
  601.                     const img = new Image();
  602.                     img.crossOrigin = 'anonymous';
  603.                     img.onload = () => {
  604.                         catImages[type] = img;
  605.                         loaded++;
  606.                         if (loaded >= total) resolve();
  607.                     };
  608.                     img.onerror = () => {
  609.                         loaded++;
  610.                         if (loaded >= total) resolve();
  611.                     };
  612.                     img.src = catImageUrls[type];
  613.                 });
  614.             });
  615.         }
  616.          
  617.         // 页面切换
  618.         function showPage(pageId) {
  619.             document.querySelectorAll('.page').forEach(p => p.classList.remove('active'));
  620.             document.getElementById(pageId).classList.add('active');
  621.         }
  622.          
  623.         // 开始游戏
  624.         function startGame(type) {
  625.             currentCatType = type;
  626.             const config = catConfigs[type];
  627.             
  628.             // 更新顶部徽章
  629.             badgeCatImg.src = catImageUrls[type];
  630.             badgeCatName.textContent = config.name;
  631.             difficultyText.textContent = config.difficulty;
  632.             hintEmoji.textContent = config.emoji;
  633.             hintText.textContent = `${config.name}每次走${config.steps}步`;
  634.             
  635.             // 狸花猫特殊提示
  636.             const lihuaHint = document.getElementById('lihuaHint');
  637.             if (type === 'lihua') {
  638.                 lihuaHint.style.display = 'flex';
  639.             } else {
  640.                 lihuaHint.style.display = 'none';
  641.             }
  642.             
  643.             // 初始化游戏
  644.             resizeCanvas();
  645.             initMap();
  646.             
  647.             // 切换到游戏页面
  648.             showPage('gamePage');
  649.         }
  650.          
  651.         // 返回选择页面
  652.         function goBack() {
  653.             if (aniId) cancelAnimationFrame(aniId);
  654.             showPage('selectPage');
  655.         }
  656.          
  657.         // 重新开始游戏
  658.         function restartGame() {
  659.             initMap();
  660.         }
  661.          
  662.         function initMap() {
  663.             if (aniId) cancelAnimationFrame(aniId);
  664.             isOver = false; isAnimating = false;
  665.             moveCount = 0;
  666.             moveCountDisplay.textContent = '0';
  667.             
  668.             const config = catConfigs[currentCatType];
  669.             statusText.innerText = `选择${config.name},点击蓝点围住它!`;
  670.             statusText.className = "status-text";
  671.             restartHint.className = "restart-hint";
  672.             
  673.             map = Array.from({ length: ROWS }, () => Array(COLS).fill(0));
  674.             let minObs = currentCatType === 'lihua' ? 10 : currentCatType === 'tabby' ? 11 : 12;
  675.             let maxObs = currentCatType === 'lihua' ? 14 : currentCatType === 'tabby' ? 15 : 18;
  676.             let count = minObs + Math.floor(Math.random() * (maxObs - minObs + 1));
  677.             
  678.             while (count > 0) {
  679.                 let r = Math.floor(Math.random() * ROWS), c = Math.floor(Math.random() * COLS);
  680.                 if (map[r][c] === 0 && !(r === 5 && c === 5)) {
  681.                     map[r][c] = 1;
  682.                     count--;
  683.                 }
  684.             }
  685.             catPos = { r: 5, c: 5 };
  686.             catDrawPos = getXY(catPos.r, catPos.c);
  687.             catPositionDisplay.textContent = `(5,5)`;
  688.             startLoop();
  689.         }
  690.    
  691.         function getXY(r, c) {
  692.             const x = RADIUS + 6 + c * (RADIUS * 2 + GAP) + (r % 2 === 1 ? RADIUS : 0);
  693.             const y = RADIUS + 6 + r * (RADIUS * 2 + 4);
  694.             return { x, y };
  695.         }
  696.    
  697.         // 绘制猫咪
  698.         function drawCat(x, y, dir, isRunning) {
  699.             if (isNaN(x) || isNaN(y)) return;
  700.             ctx.save();
  701.             
  702.             const config = catConfigs[currentCatType];
  703.             const t = Date.now();
  704.             let bobY = isRunning ? Math.sin(t / 35) * 3 : Math.sin(t / 400) * 0.8;
  705.    
  706.             ctx.translate(x, y + bobY);
  707.             ctx.scale(dir, 1);
  708.    
  709.             const furColor = config.furColor;
  710.             const bellyColor = config.bellyColor;
  711.             
  712.             // 身体
  713.             ctx.fillStyle = furColor;
  714.             ctx.beginPath();
  715.             ctx.roundRect(-12, -6, 24, 14, 6);
  716.             ctx.fill();
  717.             
  718.             // 肚子
  719.             ctx.fillStyle = bellyColor;
  720.             ctx.beginPath();
  721.             ctx.ellipse(0, 2, 8, 4, 0, 0, Math.PI*2);
  722.             ctx.fill();
  723.             
  724.             // 条纹
  725.             if (currentCatType === 'tabby' || currentCatType === 'lihua') {
  726.                 ctx.strokeStyle = currentCatType === 'tabby' ? '#2F2F2F' : '#3D2314';
  727.                 ctx.lineWidth = 1.5;
  728.                 ctx.beginPath();
  729.                 ctx.moveTo(-6, -5); ctx.lineTo(-6, 4);
  730.                 ctx.moveTo(0, -5); ctx.lineTo(0, 4);
  731.                 ctx.moveTo(6, -5); ctx.lineTo(6, 4);
  732.                 ctx.stroke();
  733.             }
  734.    
  735.             // 头
  736.             ctx.fillStyle = furColor;
  737.             ctx.beginPath();
  738.             ctx.arc(10, -5, 9, 0, Math.PI * 2);
  739.             ctx.fill();
  740.    
  741.             // 耳朵
  742.             ctx.beginPath(); ctx.moveTo(7, -12); ctx.lineTo(13, -12); ctx.lineTo(10, -20); ctx.fill();
  743.             ctx.beginPath(); ctx.moveTo(12, -10); ctx.lineTo(18, -8); ctx.lineTo(16, -16); ctx.fill();
  744.             
  745.             // 耳内
  746.             ctx.fillStyle = '#FFB6C1';
  747.             ctx.beginPath(); ctx.moveTo(8, -12); ctx.lineTo(11, -12); ctx.lineTo(9.5, -17); ctx.fill();
  748.             ctx.beginPath(); ctx.moveTo(13, -10); ctx.lineTo(16, -9); ctx.lineTo(15, -14); ctx.fill();
  749.    
  750.             // 眼睛
  751.             ctx.fillStyle = "#FFF";
  752.             ctx.beginPath(); ctx.arc(13, -6, 2, 0, Math.PI*2); ctx.fill();
  753.             ctx.fillStyle = config.eyeColor;
  754.             ctx.beginPath(); ctx.arc(14, -6, 1, 0, Math.PI*2); ctx.fill();
  755.    
  756.             // 鼻子
  757.             ctx.fillStyle = '#FFB6C1';
  758.             ctx.beginPath();
  759.             ctx.moveTo(17, -3);
  760.             ctx.lineTo(15, -1);
  761.             ctx.lineTo(19, -1);
  762.             ctx.closePath();
  763.             ctx.fill();
  764.    
  765.             // 腮红
  766.             ctx.fillStyle = 'rgba(255, 182, 193, 0.4)';
  767.             ctx.beginPath(); ctx.ellipse(19, -1, 2.5, 1.5, 0, 0, Math.PI*2); ctx.fill();
  768.             ctx.beginPath(); ctx.ellipse(7, -1, 2.5, 1.5, 0, 0, Math.PI*2); ctx.fill();
  769.    
  770.             // 腿
  771.             ctx.fillStyle = furColor;
  772.             ctx.beginPath(); ctx.roundRect(7, 5, 4, 8, 2); ctx.fill();
  773.             ctx.beginPath(); ctx.roundRect(-10, 5, 4, 8, 2); ctx.fill();
  774.    
  775.             // 尾巴
  776.             ctx.lineWidth = 3; ctx.strokeStyle = furColor; ctx.lineCap = "round";
  777.             ctx.beginPath(); ctx.moveTo(-12, -2); ctx.quadraticCurveTo(-20, -6, -18, -14); ctx.stroke();
  778.    
  779.             ctx.restore();
  780.         }
  781.    
  782.         function startLoop() {
  783.             const loop = () => {
  784.                 ctx.clearRect(0, 0, canvas.width, canvas.height);
  785.                 for (let r = 0; r < ROWS; r++) {
  786.                     for (let c = 0; c < COLS; c++) {
  787.                         const { x, y } = getXY(r, c);
  788.                         ctx.beginPath(); ctx.arc(x, y, RADIUS, 0, Math.PI * 2);
  789.                         ctx.fillStyle = map[r][c] === 1 ? "#34495e" : "#b3d9ff"; ctx.fill();
  790.                     }
  791.                 }
  792.                 const catBase = getXY(catPos.r, catPos.c);
  793.                 if (!isAnimating || (isAnimating && !isOver)) {
  794.                     ctx.beginPath(); ctx.arc(catBase.x, catBase.y, RADIUS, 0, Math.PI*2);
  795.                     ctx.fillStyle = "#b3d9ff"; ctx.fill();
  796.                 }
  797.                 drawCat(catDrawPos.x, catDrawPos.y, catDir, isAnimating && !isOver);
  798.                 aniId = requestAnimationFrame(loop);
  799.             };
  800.             loop();
  801.         }
  802.    
  803.         function getAdj(r, c) {
  804.             let n = [[r, c-1], [r, c+1]];
  805.             if (r % 2 === 0) n.push([r-1, c-1], [r-1, c], [r+1, c-1], [r+1, c]);
  806.             else n.push([r-1, c], [r-1, c+1], [r+1, c], [r+1, c+1]);
  807.             return n.filter(p => p[0]>=0 && p[0]<ROWS && p[1]>=0 && p[1]<COLS);
  808.         }
  809.    
  810.         function findSimplePath(startR, startC) {
  811.             let queue = [{ r: startR, c: startC, path: [] }], visited = new Set([`${startR},${startC}`]);
  812.             while (queue.length > 0) {
  813.                 let curr = queue.shift();
  814.                 if (curr.r === 0 || curr.r === ROWS - 1 || curr.c === 0 || curr.c === COLS - 1) return curr.path;
  815.                 for (let [nr, nc] of getAdj(curr.r, curr.c)) {
  816.                     if (map[nr][nc] === 0 && !visited.has(`${nr},${nc}`)) {
  817.                         visited.add(`${nr},${nc}`);
  818.                         queue.push({ r: nr, c: nc, path: curr.path.concat({ r: nr, c: nc }) });
  819.                     }
  820.                 }
  821.             }
  822.             return null;
  823.         }
  824.    
  825.         function catMove() {
  826.             if (isOver || isAnimating) return;
  827.             
  828.             const config = catConfigs[currentCatType];
  829.             let path = findSimplePath(catPos.r, catPos.c);
  830.             
  831.             if (!path || path.length === 0) {
  832.                 // 猫被困住了,检查放置次数
  833.                 if (moveCount <= 13) {
  834.                     isOver = true;
  835.                     const winMessages = [
  836.                         `${config.name}已经无路可走,你赢了!`,
  837.                         `太棒了!${config.name}被困住了!`,
  838.                         `成功围住${config.name}!`
  839.                     ];
  840.                     statusText.innerText = winMessages[Math.floor(Math.random() * winMessages.length)];
  841.                     statusText.className = "status-text win";
  842.                 } else {
  843.                     isOver = true;
  844.                     statusText.innerText = `超过13步限制,${config.name}成功坚守!`;
  845.                     statusText.className = "status-text lose";
  846.                 }
  847.                 restartHint.className = "restart-hint show";
  848.                 return;
  849.             }
  850.             
  851.             isAnimating = true;
  852.             
  853.             // 狸花猫特殊机制:当周围逃跑路线 ≤3 时被激怒跳两步
  854.             let stepsToMove = 1;
  855.             if (currentCatType === 'lihua' && config.angrySteps) {
  856.                 const escapeRoutes = countEscapeRoutes(catPos.r, catPos.c);
  857.                 if (escapeRoutes <= 3) {
  858.                     stepsToMove = 2;
  859.                     statusText.innerText = `狸花猫被激怒了!跳两步逃跑!`;
  860.                 }
  861.             }
  862.             
  863.             // 执行移动
  864.             const actualSteps = Math.min(stepsToMove, path.length);
  865.             animateCatMove(path.slice(0, actualSteps), () => {
  866.                 isAnimating = false;
  867.             });
  868.         }
  869.          
  870.         // 计算某位置的可逃跑方向数量
  871.         function countEscapeRoutes(r, c) {
  872.             let count = 0;
  873.             const adj = getAdj(r, c);
  874.             for (let [nr, nc] of adj) {
  875.                 if (map[nr][nc] === 0) {
  876.                     count++;
  877.                 }
  878.             }
  879.             return count;
  880.         }
  881.          
  882.         function animateCatMove(pathSegments, onComplete) {
  883.             if (pathSegments.length === 0) {
  884.                 onComplete();
  885.                 return;
  886.             }
  887.             
  888.             const config = catConfigs[currentCatType];
  889.             const segment = pathSegments[0];
  890.             const startXY = { ...catDrawPos };
  891.             const endXY = getXY(segment.r, segment.c);
  892.             catDir = endXY.x < startXY.x ? -1 : 1;
  893.             catPos = { r: segment.r, c: segment.c };
  894.             catPositionDisplay.textContent = `(${segment.r},${segment.c})`;
  895.             
  896.             let startTime = null;
  897.             const duration = config.speed;
  898.             
  899.             const aniStep = (time) => {
  900.                 if (!startTime) startTime = time;
  901.                 const p = Math.min((time - startTime) / duration, 1);
  902.                 catDrawPos.x = startXY.x + (endXY.x - startXY.x) * p;
  903.                 catDrawPos.y = startXY.y + (endXY.y - startXY.y) * p;
  904.                  
  905.                 if (p < 1) {
  906.                     requestAnimationFrame(aniStep);
  907.                 } else {
  908.                     if (pathSegments.length > 1) {
  909.                         animateCatMove(pathSegments.slice(1), onComplete);
  910.                     } else {
  911.                         if (catPos.r === 0 || catPos.r === ROWS-1 || catPos.c === 0 || catPos.c === COLS-1) {
  912.                             // 猫逃跑了,检查放置次数
  913.                             if (moveCount <= 13) {
  914.                                 isOver = true;
  915.                                 const loseMessages = [
  916.                                     `哎呀,${config.name}逃跑了!`,
  917.                                     `${config.name}跑掉了,下次再战!`,
  918.                                     `被${config.name}溜走了~`
  919.                                 ];
  920.                                 statusText.innerText = loseMessages[Math.floor(Math.random() * loseMessages.length)];
  921.                                 statusText.className = "status-text lose";
  922.                             } else {
  923.                                 isOver = true;
  924.                                 statusText.innerText = `超过13步限制,${config.name}成功逃脱!`;
  925.                                 statusText.className = "status-text lose";
  926.                             }
  927.                             restartHint.className = "restart-hint show";
  928.                         } else {
  929.                             onComplete();
  930.                         }
  931.                     }
  932.                 }
  933.             };
  934.             requestAnimationFrame(aniStep);
  935.         }
  936.    
  937.         canvas.addEventListener('click', (e) => {
  938.             if (isOver) { initMap(); return; }
  939.             if (isAnimating) return;
  940.             
  941.             const rect = canvas.getBoundingClientRect();
  942.             const scaleX = canvas.width / rect.width;
  943.             const scaleY = canvas.height / rect.height;
  944.             const mX = (e.clientX - rect.left) * scaleX;
  945.             const mY = (e.clientY - rect.top) * scaleY;
  946.             
  947.             for (let r = 0; r < ROWS; r++) {
  948.                 for (let c = 0; c < COLS; c++) {
  949.                     const { x, y } = getXY(r, c);
  950.                     if (Math.hypot(mX - x, mY - y) < RADIUS + 8) {
  951.                         if (map[r][c] === 0 && !(r === catPos.r && c === catPos.c)) {
  952.                             const config = catConfigs[currentCatType];
  953.                             moveCount++;
  954.                             moveCountDisplay.textContent = moveCount;
  955.                              
  956.                             // 检查是否超过13步限制
  957.                             if (moveCount > 13) {
  958.                                 isOver = true;
  959.                                 statusText.innerText = `超过13步限制,${config.name}成功坚守!`;
  960.                                 statusText.className = "status-text lose";
  961.                                 restartHint.className = "restart-hint show";
  962.                                 return;
  963.                             }
  964.                              
  965.                             statusText.innerText = `放置障碍物,${config.name}要动了!`;
  966.                             map[r][c] = 1;
  967.                             catMove();
  968.                             return;
  969.                         }
  970.                     }
  971.                 }
  972.             }
  973.         });
  974.          
  975.         // 监听窗口大小变化
  976.         window.addEventListener('resize', () => {
  977.             if (document.getElementById('gamePage').classList.contains('active')) {
  978.                 resizeCanvas();
  979.             }
  980.         });
  981.          
  982.         // 初始化
  983.         preloadCatImages();
  984.     </script>
  985. </body>
  986. </html>
复制代码


回复

您需要登录后才可以回帖 登录 | 立即注册 微信登录

本版积分规则

您需要 登录 后才可以回复,轻松玩转社区,没有帐号?立即注册
快速回复
关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表