返回列表 发布新帖

一款摸鱼时开发的逗逼贪吃蛇游戏!

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

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

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

×

一款摸鱼时开发的逗逼贪吃蛇游戏!

一款摸鱼时开发的逗逼贪吃蛇游戏!

一款摸鱼时开发的逗逼贪吃蛇游戏!

一款摸鱼时开发的逗逼贪吃蛇游戏!

特点:
  • 蛇有表情变化 - 开心、舔嘴唇、惊讶、死亡时的表情
  • 各种搞笑食物 - 汉堡、披萨、奶茶、辣条等
  • 夸张的视觉效果 - 吃到食物时屏幕震动、爆炸效果
  • 逗逼的死亡动画 - 蛇会翻白眼、弹出搞笑文字
  • 积分系统 - 吃不同食物得分不同
  • 速度加快 - 越来越快增加挑战
  • 搞笑的音效提示(用 emoji 和动画模拟)
  • 排行榜[mw

  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">
  6.     <title>逗逼贪吃蛇 - 笑死人不偿命!</title>
  7.     <style>
  8.         @import url('https://fonts.googleapis.cn/css2?family=Noto+Sans+SC:wght@400;700;900&display=swap');
  9.          
  10.         * {
  11.             margin: 0;
  12.             padding: 0;
  13.             box-sizing: border-box;
  14.         }
  15.          
  16.         body {
  17.             font-family: 'Noto Sans SC', sans-serif;
  18.             min-height: 100vh;
  19.             background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  20.             display: flex;
  21.             flex-direction: column;
  22.             align-items: center;
  23.             justify-content: center;
  24.             overflow: hidden;
  25.             position: relative;
  26.         }
  27.          
  28.         /* 背景装饰 */
  29.         .bg-decoration {
  30.             position: fixed;
  31.             top: 0;
  32.             left: 0;
  33.             width: 100%;
  34.             height: 100%;
  35.             pointer-events: none;
  36.             z-index: 0;
  37.         }
  38.          
  39.         .star {
  40.             position: absolute;
  41.             background: white;
  42.             border-radius: 50%;
  43.             animation: twinkle 2s infinite;
  44.         }
  45.          
  46.         @keyframes twinkle {
  47.             0%, 100% { opacity: 0.3; }
  48.             50% { opacity: 1; }
  49.         }
  50.          
  51.         /* 标题 */
  52.         .title {
  53.             font-size: 3rem;
  54.             font-weight: 900;
  55.             background: linear-gradient(45deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3);
  56.             -webkit-background-clip: text;
  57.             -webkit-text-fill-color: transparent;
  58.             background-clip: text;
  59.             text-shadow: 0 0 30px rgba(255, 107, 107, 0.5);
  60.             margin-bottom: 10px;
  61.             animation: bounce 1s ease infinite;
  62.             z-index: 10;
  63.         }
  64.          
  65.         @keyframes bounce {
  66.             0%, 100% { transform: translateY(0); }
  67.             50% { transform: translateY(-10px); }
  68.         }
  69.          
  70.         .subtitle {
  71.             color: #feca57;
  72.             font-size: 1.2rem;
  73.             margin-bottom: 20px;
  74.             z-index: 10;
  75.         }
  76.          
  77.         /* 游戏容器 */
  78.         .game-wrapper {
  79.             position: relative;
  80.             z-index: 10;
  81.         }
  82.          
  83.         .game-info {
  84.             display: flex;
  85.             justify-content: space-between;
  86.             align-items: center;
  87.             width: 100%;
  88.             max-width: 750px;
  89.             margin-bottom: 15px;
  90.             padding: 0 10px;
  91.         }
  92.          
  93.         .score-display {
  94.             background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  95.             padding: 10px 25px;
  96.             border-radius: 50px;
  97.             color: white;
  98.             font-weight: 700;
  99.             font-size: 1.3rem;
  100.             box-shadow: 0 5px 20px rgba(102, 126, 234, 0.4);
  101.             display: flex;
  102.             align-items: center;
  103.             gap: 10px;
  104.         }
  105.          
  106.         .score-display span {
  107.             font-size: 1.5rem;
  108.         }
  109.          
  110.         .high-score {
  111.             background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  112.             padding: 10px 20px;
  113.             border-radius: 50px;
  114.             color: white;
  115.             font-weight: 700;
  116.             font-size: 1rem;
  117.             box-shadow: 0 5px 20px rgba(245, 87, 108, 0.4);
  118.         }
  119.          
  120.         .game-container {
  121.             position: relative;
  122.             background: linear-gradient(145deg, #1e3a5f 0%, #0d1b2a 100%);
  123.             border-radius: 20px;
  124.             padding: 15px;
  125.             box-shadow:
  126.                 0 0 0 4px rgba(255, 255, 255, 0.1),
  127.                 0 20px 60px rgba(0, 0, 0, 0.5),
  128.                 inset 0 0 60px rgba(72, 219, 251, 0.1);
  129.         }
  130.          
  131.         #gameCanvas {
  132.             display: block;
  133.             border-radius: 12px;
  134.             background: linear-gradient(180deg, #0a1628 0%, #1a2f4a 100%);
  135.         }
  136.          
  137.         /* 屏幕震动效果 */
  138.         .shake {
  139.             animation: shake 0.3s ease-in-out;
  140.         }
  141.          
  142.         @keyframes shake {
  143.             0%, 100% { transform: translateX(0); }
  144.             25% { transform: translateX(-10px) rotate(-1deg); }
  145.             75% { transform: translateX(10px) rotate(1deg); }
  146.         }
  147.          
  148.         /* 开始/结束界面 */
  149.         .overlay {
  150.             position: absolute;
  151.             top: 0;
  152.             left: 0;
  153.             width: 100%;
  154.             height: 100%;
  155.             background: rgba(0, 0, 0, 0.85);
  156.             border-radius: 12px;
  157.             display: flex;
  158.             flex-direction: column;
  159.             align-items: center;
  160.             justify-content: center;
  161.             z-index: 100;
  162.             backdrop-filter: blur(10px);
  163.         }
  164.          
  165.         .overlay.hidden {
  166.             display: none;
  167.         }
  168.          
  169.         .overlay-title {
  170.             font-size: 2.5rem;
  171.             font-weight: 900;
  172.             margin-bottom: 20px;
  173.             text-align: center;
  174.         }
  175.          
  176.         .start-title {
  177.             background: linear-gradient(45deg, #ff6b6b, #feca57);
  178.             -webkit-background-clip: text;
  179.             -webkit-text-fill-color: transparent;
  180.             background-clip: text;
  181.         }
  182.          
  183.         .gameover-title {
  184.             background: linear-gradient(45deg, #ff4757, #ff6b81);
  185.             -webkit-background-clip: text;
  186.             -webkit-text-fill-color: transparent;
  187.             background-clip: text;
  188.             animation: pulse 0.5s ease infinite;
  189.         }
  190.          
  191.         @keyframes pulse {
  192.             0%, 100% { transform: scale(1); }
  193.             50% { transform: scale(1.05); }
  194.         }
  195.          
  196.         .final-score {
  197.             font-size: 1.5rem;
  198.             color: #feca57;
  199.             margin-bottom: 10px;
  200.         }
  201.          
  202.         .death-message {
  203.             font-size: 1.2rem;
  204.             color: #ff6b6b;
  205.             margin-bottom: 20px;
  206.             font-weight: 700;
  207.         }
  208.          
  209.         .start-btn {
  210.             background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  211.             border: none;
  212.             padding: 15px 50px;
  213.             font-size: 1.3rem;
  214.             font-weight: 700;
  215.             color: white;
  216.             border-radius: 50px;
  217.             cursor: pointer;
  218.             transition: all 0.3s ease;
  219.             box-shadow: 0 10px 30px rgba(102, 126, 234, 0.4);
  220.             font-family: inherit;
  221.         }
  222.          
  223.         .start-btn:hover {
  224.             transform: translateY(-5px) scale(1.05);
  225.             box-shadow: 0 15px 40px rgba(102, 126, 234, 0.6);
  226.         }
  227.          
  228.         .start-btn:active {
  229.             transform: translateY(0) scale(0.98);
  230.         }
  231.          
  232.         .instructions {
  233.             color: #a0a0a0;
  234.             font-size: 0.9rem;
  235.             margin-top: 20px;
  236.             text-align: center;
  237.             line-height: 1.6;
  238.         }
  239.          
  240.         .instructions kbd {
  241.             background: #333;
  242.             padding: 3px 8px;
  243.             border-radius: 5px;
  244.             font-family: inherit;
  245.         }
  246.          
  247.         /* 表情气泡 */
  248.         .emoji-bubble {
  249.             position: fixed;
  250.             font-size: 3rem;
  251.             pointer-events: none;
  252.             animation: floatUp 1s ease-out forwards;
  253.             z-index: 1000;
  254.         }
  255.          
  256.         @keyframes floatUp {
  257.             0% { opacity: 1; transform: translateY(0) scale(1); }
  258.             100% { opacity: 0; transform: translateY(-100px) scale(1.5); }
  259.         }
  260.          
  261.         /* 控制提示 */
  262.         .controls-hint {
  263.             display: flex;
  264.             gap: 15px;
  265.             margin-top: 15px;
  266.             flex-wrap: wrap;
  267.             justify-content: center;
  268.             z-index: 10;
  269.         }
  270.          
  271.         .control-key {
  272.             background: rgba(255, 255, 255, 0.1);
  273.             padding: 8px 15px;
  274.             border-radius: 10px;
  275.             color: #888;
  276.             font-size: 0.85rem;
  277.             display: flex;
  278.             align-items: center;
  279.             gap: 8px;
  280.         }
  281.          
  282.         .control-key kbd {
  283.             background: #333;
  284.             padding: 5px 10px;
  285.             border-radius: 5px;
  286.             color: white;
  287.             font-family: inherit;
  288.         }
  289.          
  290.         /* 速度指示器 */
  291.         .speed-indicator {
  292.             position: absolute;
  293.             top: -30px;
  294.             right: 0;
  295.             background: linear-gradient(135deg, #ff6b6b, #ee5a24);
  296.             padding: 5px 15px;
  297.             border-radius: 20px;
  298.             color: white;
  299.             font-size: 0.8rem;
  300.             font-weight: 700;
  301.             opacity: 0;
  302.             transition: opacity 0.3s;
  303.         }
  304.          
  305.         .speed-indicator.visible {
  306.             opacity: 1;
  307.         }
  308.          
  309.         /* 连击提示 */
  310.         .combo-popup {
  311.             position: absolute;
  312.             font-size: 2rem;
  313.             font-weight: 900;
  314.             color: #feca57;
  315.             text-shadow: 0 0 20px rgba(254, 202, 87, 0.8);
  316.             pointer-events: none;
  317.             animation: comboAnim 0.8s ease-out forwards;
  318.             z-index: 50;
  319.         }
  320.          
  321.         @keyframes comboAnim {
  322.             0% { opacity: 1; transform: scale(0.5); }
  323.             50% { transform: scale(1.2); }
  324.             100% { opacity: 0; transform: scale(1) translateY(-50px); }
  325.         }
  326.          
  327.         /* 响应式 */
  328.         @media (max-width: 650px) {
  329.             .title { font-size: 2rem; }
  330.             .subtitle { font-size: 1rem; }
  331.             .score-display { padding: 8px 15px; font-size: 1rem; }
  332.             .high-score { padding: 8px 12px; font-size: 0.85rem; }
  333.             .game-container { padding: 10px; }
  334.             .controls-hint { display: none; }
  335.         }
  336.     </style>
  337. </head>
  338. <body>
  339.     <!-- 背景装饰 -->
  340.     <div class="bg-decoration" id="bgDecoration"></div>
  341.      
  342.     <h1 class="title">&#128013; 逗逼贪吃蛇 &#128013;</h1>
  343.     <p class="subtitle" id="subtitle">笑死人不偿命版</p>
  344.      
  345.     <div class="game-wrapper">
  346.         <div class="game-info">
  347.             <div class="score-display">
  348.                 &#127919; 得分: <span id="score">0</span>
  349.             </div>
  350.             <div class="high-score">
  351.                 &#128081; 最高: <span id="highScore">0</span>
  352.             </div>
  353.         </div>
  354.          
  355.         <div class="game-container" id="gameContainer">
  356.             <div class="speed-indicator" id="speedIndicator">&#128640; 加速中!</div>
  357.             <canvas id="gameCanvas" width="600" height="450"></canvas>
  358.             
  359.             <!-- 开始界面 -->
  360.             <div class="overlay" id="startOverlay">
  361.                 <div class="overlay-title start-title">&#128013; 贪吃蛇来啦!</div>
  362.                 <button class="start-btn" id="startBtn">开始游戏</button>
  363.                 <div class="instructions">
  364.                     <p>用 <kbd>↑</kbd> <kbd>↓</kbd> <kbd>←</kbd> <kbd>→</kbd> 或 <kbd>W</kbd> <kbd>A</kbd> <kbd>S</kbd> <kbd>D</kbd> 控制方向</p>
  365.                     <p style="margin-top: 8px;">吃遍天下美食,成为蛇中之王!</p>
  366.                 </div>
  367.             </div>
  368.             
  369.             <!-- 结束界面 -->
  370.             <div class="overlay hidden" id="gameoverOverlay">
  371.                 <div class="overlay-title gameover-title">&#128128; 被撑死了!</div>
  372.                 <div class="final-score" id="finalScore">本局得分: 0</div>
  373.                 <div class="death-message" id="deathMessage">死因: 撞墙了</div>
  374.                 <button class="start-btn" id="restartBtn">再战一局</button>
  375.             </div>
  376.         </div>
  377.          
  378.         <div class="controls-hint">
  379.             <div class="control-key"><kbd>↑↓←→</kbd> 或 <kbd>WASD</kbd> 移动</div>
  380.             <div class="control-key"><kbd>Space</kbd> 暂停</div>
  381.             <div class="control-key"><kbd>R</kbd> 重新开始</div>
  382.         </div>
  383.     </div>
  384.      
  385.     <script>
  386.         // 游戏配置
  387.         const CELL_SIZE = 18;
  388.         const GRID_WIDTH = 40;
  389.         const GRID_HEIGHT = 28;
  390.         const INITIAL_SPEED = 150;
  391.         const SPEED_INCREMENT = 3;
  392.         const MIN_SPEED = 50;
  393.          
  394.         // 食物类型和表情
  395.         const FOOD_TYPES = [
  396.             { emoji: '&#127822;', name: '苹果', points: 10, color: '#ff6b6b' },
  397.             { emoji: '&#127829;', name: '披萨', points: 15, color: '#feca57' },
  398.             { emoji: '&#127828;', name: '汉堡', points: 20, color: '#ff9f43' },
  399.             { emoji: '&#127846;', name: '冰淇淋', points: 15, color: '#ee5a24' },
  400.             { emoji: '&#127849;', name: '甜甜圈', points: 15, color: '#f368e0' },
  401.             { emoji: '&#127830;', name: '猪排', points: 25, color: '#ff9ff3' },
  402.             { emoji: '&#127836;', name: '拉面', points: 20, color: '#ffeaa7' },
  403.             { emoji: '&#127857;', name: '便当', points: 30, color: '#d63031' },
  404.             { emoji: '&#129424;', name: '大虾', points: 35, color: '#ff7675' },
  405.             { emoji: '&#127856;', name: '蛋糕', points: 25, color: '#fab1a0' },
  406.             { emoji: '&#129385;', name: '牛排', points: 40, color: '#a29bfe' },
  407.             { emoji: '&#127839;', name: '薯条', points: 12, color: '#fdcb6e' },
  408.             { emoji: '&#9749;', name: '咖啡', points: 10, color: '#6c5ce7' },
  409.             { emoji: '&#127866;', name: '啤酒', points: 15, color: '#ffeaa7' },
  410.             { emoji: '&#127830;', name: '烤串', points: 20, color: '#d63031' }
  411.         ];
  412.          
  413.         // 蛇的表情
  414.         const SNAKE_FACES = {
  415.             happy: ['(^_^)', '(&#9696;&#8255;&#9696;)', '(&#65377;&#9685;&#8255;&#9685;&#65377;)', '(●&#7447;●)'],
  416.             eating: ['(亝ω亝)', '(&#9829;&#8255;&#9829;)', '(●&#180;ω`●)', '(&#10023;ω&#10023;)'],
  417.             scared: ['(°ロ°)', '(⊙_⊙)', '(°o°)', '(⊙﹏⊙)'],
  418.             dead: ['×_×', '(T_T)', '(╥﹏╥)', '×_×'],
  419.             cool: ['(&#172;&#8255;&#172;)', '(&#864;&#9673;&#863;&#662;&#865;&#9673;)', '(&#3232;_&#3232;)', '( &#8226;_&#8226;)']
  420.         };
  421.          
  422.         // 死亡原因
  423.         const DEATH_MESSAGES = [
  424.             '死因: 撞墙了(墙壁有意见)',
  425.             '死因: 咬到自己了(自恋过度)',
  426.             '死因: 吃太饱了撑死',
  427.             '死因: 撞到尾巴(追尾全责)',
  428.             '死因: 刹车失灵',
  429.             '死因: 方向感迷失',
  430.             '死因: 吃到炸弹&#128163;',
  431.             '死因: 蛇生艰难'
  432.         ];
  433.          
  434.         // 游戏状态
  435.         let canvas, ctx;
  436.         let snake = [];
  437.         let food = null;
  438.         let direction = { x: 1, y: 0 };
  439.         let nextDirection = { x: 1, y: 0 };
  440.         let score = 0;
  441.         let highScore = localStorage.getItem('snakeHighScore') || 0;
  442.         let gameLoop = null;
  443.         let gameSpeed = INITIAL_SPEED;
  444.         let isGameRunning = false;
  445.         let isPaused = false;
  446.         let combo = 0;
  447.         let lastEmoji = '';
  448.         let currentFace = 'happy';
  449.          
  450.         // DOM元素
  451.         const scoreEl = document.getElementById('score');
  452.         const highScoreEl = document.getElementById('highScore');
  453.         const startOverlay = document.getElementById('startOverlay');
  454.         const gameoverOverlay = document.getElementById('gameoverOverlay');
  455.         const finalScoreEl = document.getElementById('finalScore');
  456.         const deathMessageEl = document.getElementById('deathMessage');
  457.         const gameContainer = document.getElementById('gameContainer');
  458.         const speedIndicator = document.getElementById('speedIndicator');
  459.         const subtitleEl = document.getElementById('subtitle');
  460.          
  461.         // 初始化
  462.         function init() {
  463.             canvas = document.getElementById('gameCanvas');
  464.             ctx = canvas.getContext('2d');
  465.             
  466.             canvas.width = GRID_WIDTH * CELL_SIZE;
  467.             canvas.height = GRID_HEIGHT * CELL_SIZE;
  468.             
  469.             highScoreEl.textContent = highScore;
  470.             
  471.             // 创建背景星星
  472.             createStars();
  473.             
  474.             // 事件监听
  475.             document.getElementById('startBtn').addEventListener('click', startGame);
  476.             document.getElementById('restartBtn').addEventListener('click', startGame);
  477.             
  478.             document.addEventListener('keydown', handleKeydown);
  479.             
  480.             // 触摸控制
  481.             setupTouchControls();
  482.             
  483.             // 随机字幕
  484.             randomSubtitle();
  485.             setInterval(randomSubtitle, 5000);
  486.         }
  487.          
  488.         // 创建背景星星
  489.         function createStars() {
  490.             const bg = document.getElementById('bgDecoration');
  491.             for (let i = 0; i < 50; i++) {
  492.                 const star = document.createElement('div');
  493.                 star.className = 'star';
  494.                 star.style.left = Math.random() * 100 + '%';
  495.                 star.style.top = Math.random() * 100 + '%';
  496.                 star.style.width = star.style.height = Math.random() * 3 + 1 + 'px';
  497.                 star.style.animationDelay = Math.random() * 2 + 's';
  498.                 bg.appendChild(star);
  499.             }
  500.         }
  501.          
  502.         // 随机字幕
  503.         const subtitles = [
  504.             '笑死人不偿命版',
  505.             '一口一个小朋友',
  506.             '蛇蛇过山车',
  507.             '吃到停不下来',
  508.             '越吃越饿版',
  509.             '疯狂干饭蛇',
  510.             '今天吃什么好呢',
  511.             '专业干饭二十年',
  512.             '嘎嘎香',
  513.             '馋哭隔壁小孩'
  514.         ];
  515.          
  516.         function randomSubtitle() {
  517.             subtitleEl.textContent = subtitles[Math.floor(Math.random() * subtitles.length)];
  518.         }
  519.          
  520.         // 开始游戏
  521.         function startGame() {
  522.             // 重置状态
  523.             snake = [
  524.                 { x: 5, y: 10 },
  525.                 { x: 4, y: 10 },
  526.                 { x: 3, y: 10 }
  527.             ];
  528.             direction = { x: 1, y: 0 };
  529.             nextDirection = { x: 1, y: 0 };
  530.             score = 0;
  531.             gameSpeed = INITIAL_SPEED;
  532.             combo = 0;
  533.             isGameRunning = true;
  534.             isPaused = false;
  535.             currentFace = 'happy';
  536.             
  537.             scoreEl.textContent = score;
  538.             startOverlay.classList.add('hidden');
  539.             gameoverOverlay.classList.add('hidden');
  540.             
  541.             spawnFood();
  542.             updateSpeedIndicator();
  543.             
  544.             if (gameLoop) clearInterval(gameLoop);
  545.             gameLoop = setInterval(update, gameSpeed);
  546.         }
  547.          
  548.         // 生成食物
  549.         function spawnFood() {
  550.             let valid = false;
  551.             while (!valid) {
  552.                 food = {
  553.                     x: Math.floor(Math.random() * GRID_WIDTH),
  554.                     y: Math.floor(Math.random() * GRID_HEIGHT),
  555.                     ...FOOD_TYPES[Math.floor(Math.random() * FOOD_TYPES.length)]
  556.                 };
  557.                  
  558.                 // 确保食物不在蛇身上
  559.                 valid = !snake.some(seg => seg.x === food.x && seg.y === food.y);
  560.             }
  561.         }
  562.          
  563.         // 游戏更新
  564.         function update() {
  565.             if (!isGameRunning || isPaused) return;
  566.             
  567.             // 更新方向
  568.             direction = { ...nextDirection };
  569.             
  570.             // 计算新头部
  571.             const head = {
  572.                 x: snake[0].x + direction.x,
  573.                 y: snake[0].y + direction.y
  574.             };
  575.             
  576.             // 检查撞墙
  577.             if (head.x < 0 || head.x >= GRID_WIDTH || head.y < 0 || head.y >= GRID_HEIGHT) {
  578.                 gameOver('撞墙了(墙壁有意见)');
  579.                 return;
  580.             }
  581.             
  582.             // 检查撞自己
  583.             if (snake.some(seg => seg.x === head.x && seg.y === head.y)) {
  584.                 gameOver('咬到自己了(自恋过度)');
  585.                 return;
  586.             }
  587.             
  588.             // 添加新头部
  589.             snake.unshift(head);
  590.             
  591.             // 检查吃食物
  592.             if (head.x === food.x && head.y === food.y) {
  593.                 eatFood();
  594.             } else {
  595.                 snake.pop();
  596.             }
  597.             
  598.             render();
  599.         }
  600.          
  601.         // 吃食物
  602.         function eatFood() {
  603.             const points = food.points;
  604.             score += points;
  605.             combo++;
  606.             
  607.             // 更新分数
  608.             scoreEl.textContent = score;
  609.             
  610.             // 更新最高分
  611.             if (score > highScore) {
  612.                 highScore = score;
  613.                 localStorage.setItem('snakeHighScore', highScore);
  614.                 highScoreEl.textContent = highScore;
  615.             }
  616.             
  617.             // 表情变化
  618.             currentFace = 'eating';
  619.             showEmojiBubble(food.emoji);
  620.             
  621.             // 连击提示
  622.             if (combo > 2) {
  623.                 showComboPopup(`&#128293; x${combo}连击!`);
  624.                 gameSpeed = Math.max(MIN_SPEED, gameSpeed - SPEED_INCREMENT);
  625.                 clearInterval(gameLoop);
  626.                 gameLoop = setInterval(update, gameSpeed);
  627.                 updateSpeedIndicator();
  628.             }
  629.             
  630.             // 屏幕震动
  631.             gameContainer.classList.add('shake');
  632.             setTimeout(() => gameContainer.classList.remove('shake'), 300);
  633.             
  634.             setTimeout(() => { currentFace = 'happy'; }, 500);
  635.             
  636.             // 加速
  637.             if (combo % 5 === 0 && combo > 0) {
  638.                 gameSpeed = Math.max(MIN_SPEED, gameSpeed - SPEED_INCREMENT);
  639.                 clearInterval(gameLoop);
  640.                 gameLoop = setInterval(update, gameSpeed);
  641.                 updateSpeedIndicator();
  642.             }
  643.             
  644.             spawnFood();
  645.         }
  646.          
  647.         // 显示表情气泡
  648.         function showEmojiBubble(emoji) {
  649.             const bubble = document.createElement('div');
  650.             bubble.className = 'emoji-bubble';
  651.             bubble.textContent = emoji;
  652.             
  653.             const rect = gameContainer.getBoundingClientRect();
  654.             bubble.style.left = rect.left + rect.width / 2 - 20 + 'px';
  655.             bubble.style.top = rect.top + rect.height / 2 + 'px';
  656.             
  657.             document.body.appendChild(bubble);
  658.             setTimeout(() => bubble.remove(), 1000);
  659.         }
  660.          
  661.         // 显示连击提示
  662.         function showComboPopup(text) {
  663.             const popup = document.createElement('div');
  664.             popup.className = 'combo-popup';
  665.             popup.textContent = text;
  666.             popup.style.left = '50%';
  667.             popup.style.top = '50%';
  668.             popup.style.transform = 'translate(-50%, -50%)';
  669.             
  670.             gameContainer.appendChild(popup);
  671.             setTimeout(() => popup.remove(), 800);
  672.         }
  673.          
  674.         // 更新速度指示器
  675.         function updateSpeedIndicator() {
  676.             if (gameSpeed < INITIAL_SPEED) {
  677.                 speedIndicator.classList.add('visible');
  678.                 const speedLevel = Math.floor((INITIAL_SPEED - gameSpeed) / SPEED_INCREMENT);
  679.                 speedIndicator.textContent = `&#128640; 速度+${speedLevel}`;
  680.             } else {
  681.                 speedIndicator.classList.remove('visible');
  682.             }
  683.         }
  684.          
  685.         // 游戏结束
  686.         function gameOver(reason) {
  687.             isGameRunning = false;
  688.             clearInterval(gameLoop);
  689.             
  690.             currentFace = 'dead';
  691.             render();
  692.             
  693.             // 显示死亡界面
  694.             setTimeout(() => {
  695.                 finalScoreEl.textContent = `本局得分: ${score}`;
  696.                 deathMessageEl.textContent = '死因: ' + reason;
  697.                  
  698.                 // 搞笑评语
  699.                 let comment = '';
  700.                 if (score < 50) {
  701.                     comment = '新手村还没出呢~';
  702.                 } else if (score < 150) {
  703.                     comment = '还行,继续加油!';
  704.                 } else if (score < 300) {
  705.                     comment = '有点东西啊!';
  706.                 } else if (score < 500) {
  707.                     comment = '干饭王!';
  708.                 } else {
  709.                     comment = '&#129412; 蛇中之神! &#129412;';
  710.                 }
  711.                 deathMessageEl.textContent += ` ${comment}`;
  712.                  
  713.                 gameoverOverlay.classList.remove('hidden');
  714.             }, 500);
  715.         }
  716.          
  717.         // 渲染
  718.         function render() {
  719.             // 清空画布
  720.             ctx.fillStyle = '#0a1628';
  721.             ctx.fillRect(0, 0, canvas.width, canvas.height);
  722.             
  723.             // 绘制网格
  724.             ctx.strokeStyle = 'rgba(72, 219, 251, 0.1)';
  725.             ctx.lineWidth = 0.5;
  726.             for (let x = 0; x <= GRID_WIDTH; x++) {
  727.                 ctx.beginPath();
  728.                 ctx.moveTo(x * CELL_SIZE, 0);
  729.                 ctx.lineTo(x * CELL_SIZE, canvas.height);
  730.                 ctx.stroke();
  731.             }
  732.             for (let y = 0; y <= GRID_HEIGHT; y++) {
  733.                 ctx.beginPath();
  734.                 ctx.moveTo(0, y * CELL_SIZE);
  735.                 ctx.lineTo(canvas.width, y * CELL_SIZE);
  736.                 ctx.stroke();
  737.             }
  738.             
  739.             // 绘制食物
  740.             if (food) {
  741.                 ctx.font = '18px Arial';
  742.                 ctx.textAlign = 'center';
  743.                 ctx.textBaseline = 'middle';
  744.                  
  745.                 const fx = food.x * CELL_SIZE + CELL_SIZE / 2;
  746.                 const fy = food.y * CELL_SIZE + CELL_SIZE / 2;
  747.                  
  748.                 // 食物光晕
  749.                 const gradient = ctx.createRadialGradient(fx, fy, 5, fx, fy, 20);
  750.                 gradient.addColorStop(0, food.color + '60');
  751.                 gradient.addColorStop(1, 'transparent');
  752.                 ctx.fillStyle = gradient;
  753.                 ctx.fillRect(food.x * CELL_SIZE - 5, food.y * CELL_SIZE - 5, CELL_SIZE + 10, CELL_SIZE + 10);
  754.                  
  755.                 // 食物emoji
  756.                 ctx.fillText(food.emoji, fx, fy);
  757.             }
  758.             
  759.             // 绘制蛇
  760.             snake.forEach((segment, index) => {
  761.                 const sx = segment.x * CELL_SIZE;
  762.                 const sy = segment.y * CELL_SIZE;
  763.                 const isHead = index === 0;
  764.                  
  765.                 // 蛇身渐变色
  766.                 const hue = 120 + (index * 2);
  767.                 const lightness = 60 - (index * 1.5);
  768.                  
  769.                 if (isHead) {
  770.                     // 蛇头
  771.                     ctx.fillStyle = '#2ecc71';
  772.                     ctx.shadowColor = '#2ecc71';
  773.                     ctx.shadowBlur = 15;
  774.                 } else {
  775.                     ctx.fillStyle = `hsl(${hue}, 70%, ${lightness}%)`;
  776.                     ctx.shadowBlur = 0;
  777.                 }
  778.                  
  779.                 // 圆角矩形
  780.                 const radius = isHead ? 8 : 6;
  781.                 roundRect(ctx, sx + 2, sy + 2, CELL_SIZE - 4, CELL_SIZE - 4, radius);
  782.                  
  783.                 // 蛇头眼睛和表情
  784.                 if (isHead) {
  785.                     ctx.shadowBlur = 0;
  786.                     const faces = SNAKE_FACES[currentFace] || SNAKE_FACES.happy;
  787.                     const face = faces[Math.floor(Math.random() * faces.length)];
  788.                      
  789.                     ctx.fillStyle = 'white';
  790.                     ctx.font = 'bold 10px Arial';
  791.                     ctx.textAlign = 'center';
  792.                     ctx.textBaseline = 'middle';
  793.                      
  794.                     // 眼睛
  795.                     const eyeOffsetX = direction.x !== 0 ? direction.x * 2 : 0;
  796.                     const eyeOffsetY = direction.y !== 0 ? direction.y * 2 : 0;
  797.                      
  798.                     ctx.fillText('●', sx + CELL_SIZE/2 - 4 - eyeOffsetX, sy + CELL_SIZE/2 - 2 - eyeOffsetY);
  799.                     ctx.fillText('●', sx + CELL_SIZE/2 + 4 - eyeOffsetX, sy + CELL_SIZE/2 - 2 - eyeOffsetY);
  800.                      
  801.                     // 表情
  802.                     ctx.font = '8px Arial';
  803.                     ctx.fillText(face, sx + CELL_SIZE/2, sy + CELL_SIZE/2 + 5);
  804.                 }
  805.             });
  806.         }
  807.          
  808.         // 圆角矩形
  809.         function roundRect(ctx, x, y, width, height, radius) {
  810.             ctx.beginPath();
  811.             ctx.moveTo(x + radius, y);
  812.             ctx.lineTo(x + width - radius, y);
  813.             ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
  814.             ctx.lineTo(x + width, y + height - radius);
  815.             ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
  816.             ctx.lineTo(x + radius, y + height);
  817.             ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
  818.             ctx.lineTo(x, y + radius);
  819.             ctx.quadraticCurveTo(x, y, x + radius, y);
  820.             ctx.closePath();
  821.             ctx.fill();
  822.         }
  823.          
  824.         // 按键处理
  825.         function handleKeydown(e) {
  826.             // 方向控制
  827.             switch(e.key) {
  828.                 case 'ArrowUp':
  829.                 case 'w':
  830.                 case 'W':
  831.                     if (direction.y !== 1) nextDirection = { x: 0, y: -1 };
  832.                     break;
  833.                 case 'ArrowDown':
  834.                 case 's':
  835.                 case 'S':
  836.                     if (direction.y !== -1) nextDirection = { x: 0, y: 1 };
  837.                     break;
  838.                 case 'ArrowLeft':
  839.                 case 'a':
  840.                 case 'A':
  841.                     if (direction.x !== 1) nextDirection = { x: -1, y: 0 };
  842.                     break;
  843.                 case 'ArrowRight':
  844.                 case 'd':
  845.                 case 'D':
  846.                     if (direction.x !== -1) nextDirection = { x: 1, y: 0 };
  847.                     break;
  848.                 case ' ':
  849.                     if (isGameRunning) {
  850.                         isPaused = !isPaused;
  851.                         if (!isPaused) {
  852.                             clearInterval(gameLoop);
  853.                             gameLoop = setInterval(update, gameSpeed);
  854.                         }
  855.                     }
  856.                     e.preventDefault();
  857.                     break;
  858.                 case 'r':
  859.                 case 'R':
  860.                     startGame();
  861.                     break;
  862.             }
  863.         }
  864.          
  865.         // 触摸控制
  866.         function setupTouchControls() {
  867.             let touchStartX = 0;
  868.             let touchStartY = 0;
  869.             
  870.             canvas.addEventListener('touchstart', (e) => {
  871.                 touchStartX = e.touches[0].clientX;
  872.                 touchStartY = e.touches[0].clientY;
  873.                 e.preventDefault();
  874.             }, { passive: false });
  875.             
  876.             canvas.addEventListener('touchmove', (e) => {
  877.                 e.preventDefault();
  878.             }, { passive: false });
  879.             
  880.             canvas.addEventListener('touchend', (e) => {
  881.                 if (!isGameRunning) return;
  882.                  
  883.                 const touchEndX = e.changedTouches[0].clientX;
  884.                 const touchEndY = e.changedTouches[0].clientY;
  885.                  
  886.                 const dx = touchEndX - touchStartX;
  887.                 const dy = touchEndY - touchStartY;
  888.                  
  889.                 if (Math.abs(dx) > Math.abs(dy)) {
  890.                     if (dx > 30 && direction.x !== -1) nextDirection = { x: 1, y: 0 };
  891.                     else if (dx < -30 && direction.x !== 1) nextDirection = { x: -1, y: 0 };
  892.                 } else {
  893.                     if (dy > 30 && direction.y !== -1) nextDirection = { x: 0, y: 1 };
  894.                     else if (dy < -30 && direction.y !== 1) nextDirection = { x: 0, y: -1 };
  895.                 }
  896.             });
  897.         }
  898.          
  899.         // 初始化游戏
  900.         init();
  901.     </script>
  902. </body>
  903. </html>
复制代码


回复

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

本版积分规则

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