生成大鱼吃小鱼游戏,能复制在微信上玩


# 大鱼吃小鱼游戏 (微信可用) 以下是一个简单的大鱼吃小鱼HTML5游戏代码,可以复制到微信中运行: ```html <!DOCTYPE html> <html> <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> body { margin: 0; padding: 0; overflow: hidden; background-color: #87CEEB; touch-action: none; } canvas { display: block; } #score { position: absolute; top: 10px; left: 10px; color: white; font-size: 20px; font-family: Arial; } #gameOver { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: white; font-size: 30px; font-family: Arial; text-align: center; display: none; } #restart { margin-top: 20px; padding: 10px 20px; background-color: #4CAF50; color: white; border: none; border-radius: 5px; font-size: 20px; cursor: pointer; } </style> </head> <body> <div id="score">得分: 0</div> <div id="gameOver"> 游戏结束<br> 最终得分: <span id="finalScore">0</span><br> <button id="restart">重新开始</button> </div> <canvas id="gameCanvas"></canvas> <script> const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); const scoreElement = document.getElementById('score'); const gameOverElement = document.getElementById('gameOver'); const finalScoreElement = document.getElementById('finalScore'); const restartButton = document.getElementById('restart'); // 设置画布大小为窗口大小 canvas.width = window.innerWidth; canvas.height = window.innerHeight; // 游戏变量 let score = 0; let gameRunning = true; // 玩家鱼 const player = { x: canvas.width / 2, y: canvas.height / 2, size: 20, color: '#FF6347', speed: 5 }; // 食物鱼数组 let foods = []; // 触摸/鼠标位置 let targetX = player.x; let targetY = player.y; // 监听触摸/鼠标移动 canvas.addEventListener('mousemove', (e) => { targetX = e.clientX; targetY = e.clientY; }); canvas.addEventListener('touchmove', (e) => { e.preventDefault(); targetX = e.touches[0].clientX; targetY = e.touches[0].clientY; }, { passive: false }); // 重新开始游戏 restartButton.addEventListener('click', () => { score = 0; player.size = 20; foods = []; gameRunning = true; gameOverElement.style.display = 'none'; scoreElement.textContent = '得分: 0'; animate(); }); // 生成食物鱼 function spawnFood() { if (Math.random() < 0.03 && foods.length < 15) { const size = Math.random() * 15 + 5; let x, y; // 确保食物不会在玩家附近生成 do { x = Math.random() * (canvas.width - size * 2) + size; y = Math.random() * (canvas.height - size * 2) + size; } while (Math.sqrt((x - player.x) 2 + (y - player.y) 2) < 100); const speed = Math.random() * 2 + 1; const angle = Math.random() * Math.PI * 2; const color = `hsl(${Math.random() * 360}, 70%, 50%)`; foods.push({ x, y, size, speedX: Math.cos(angle) * speed, speedY: Math.sin(angle) * speed, color }); } } // 更新游戏状态 function update() { if (!gameRunning) return; // 移动玩家鱼 const dx = targetX - player.x; const dy = targetY - player.y; const distance = Math.sqrt(dx * dx + dy * dy); if (distance > player.speed) { player.x += dx / distance * player.speed; player.y += dy / distance * player.speed; } else { player.x = targetX; player.y = targetY; } // 边界检查 player.x = Math.max(player.size, Math.min(canvas.width - player.size, player.x)); player.y = Math.max(player.size, Math.min(canvas.height - player.size, player.y)); // 更新食物鱼 for (let i = 0; i < foods.length; i++) { const food = foods[i]; // 移动食物鱼 food.x += food.speedX; food.y += food.speedY; // 边界反弹 if (food.x <= food.size || food.x >= canvas.width - food.size) { food.speedX *= -1; } if (food.y <= food.size || food.y >= canvas.height - food.size) { food.speedY *= -1; } // 检测碰撞 const distance = Math.sqrt( Math.pow(player.x - food.x, 2) + Math.pow(player.y - food.y, 2) ); if (distance < player.size + food.size) { if (player.size > food.size * 1.2) { // 玩家吃掉食物 player.size += food.size * 0.2; score += Math.floor(food.size); scoreElement.textContent = `得分: ${score}`; foods.splice(i, 1); i--; } else if (food.size > player.size * 1.2) { // 食物吃掉玩家 gameRunning = false; finalScoreElement.textContent = score; gameOverElement.style.display = 'block'; } } } // 生成新食物 spawnFood(); } // 渲染游戏 function render() { // 清空画布 ctx.clearRect(0, 0, canvas.width, canvas.height); // 绘制 ctx.fillStyle = '#87CEEB'; ctx.fillRect(0, 0, canvas.width, canvas.height); // 绘制玩家鱼 ctx.fillStyle = player.color; ctx.beginPath(); ctx.arc(player.x, player.y, player.size, 0, Math.PI * 2); ctx.fill(); // 绘制鱼尾 const angle = Math.atan2(targetY - player.y, targetX - player.x); ctx.beginPath(); ctx.moveTo(player.x, player.y); ctx.lineTo( player.x - Math.cos(angle) * player.size * 1.5, player.y - Math.sin(angle) * player.size * 1.5 ); ctx.lineWidth = player.size / 2; ctx.strokeStyle = player.color; ctx.stroke(); // 绘制食物鱼 for (const food of foods) { ctx.fillStyle = food.color; ctx.beginPath(); ctx.arc(food.x, food.y, food.size, 0, Math.PI * 2); ctx.fill(); // 绘制鱼尾 const foodAngle = Math.atan2(food.speedY, food.speedX); ctx.beginPath(); ctx.moveTo(food.x, food.y); ctx.lineTo( food.x - Math.cos(foodAngle) * food.size * 1.5, food.y - Math.sin(foodAngle) * food.size * 1.5 ); ctx.lineWidth = food.size / 2; ctx.strokeStyle = food.color; ctx.stroke(); } } // 游戏循环 function animate() { if (!gameRunning) return; update(); render(); requestAnimationFrame(animate); } // 开始游戏 animate(); // 窗口大小改变时调整画布大小 window.addEventListener('resize', () => { canvas.width = window.innerWidth; canvas.height = window.innerHeight; }); </script> </body> </html> ``` ## 使用说明 1. 将上面的代码复制到一个文本编辑器中 2. 保存为 `.html` 文件 3. 在微信中打开该文件(可以通过文件传输助手发送给自己) 4. 点击文件即可在微信内置浏览器中运行游戏 ## 游戏规则 - 控制你的鱼(红色)移动去吃比自己小的鱼 - 避免接触比自己大的鱼 - 每吃掉一条鱼会增加你的分数和体型 - 被更大的鱼吃掉游戏结束 ## 额外注意事项 1. 游戏中的碰撞检测基于圆形碰撞,确保计算距离时使用勾股定理 2. 食物鱼的生成位置会避开玩家鱼,防止突然出现在玩家面前 3. 鱼的移动速度与大小无关,但玩家鱼的速度是恒定的 [2025-06-06 19:53:28 | AI写代码神器 | 2151点数解答]
- 年会表演串词,年会节目清单 1、陈德光:诗朗诵《旗帜》5分钟 2、财务、后勤部:舞蹈《谁是我的新郎》4分钟 3、销售部:演唱《苹果香》5分钟 4、游戏:诸葛帽吃糖 5个人 一轮 10分钟 5、标书、采购部:《三句半》3分钟 6、技术部:舞蹈《wave》4分钟 7、销售部:《魔术》15分钟 8、彩虹圈转光盘 (只限于男生)4个人 一轮 10分钟 9、技术部:脱口秀 20分钟 10、销售部:《吃香蕉》3分钟 11、财务、后勤部:合唱《感恩的心》4分钟 12、游戏:喊话吹蜡烛(指定人)2个人 一轮 5分钟 13、标书、采购部:朗诵《我爱上班》 3分钟 11、销售部:邓腾龙《青花瓷》4分钟 14、相声新闻晚知道10分钟 15、游戏:摸麻将4个人 一轮 5分钟 16、大合唱:相亲相爱一家人5分钟,字数:200字(206点数解答 | 2025-01-08 10:59:43)229
- 题目描述 现有三条边长 a , b , c a,b,c,编写程序判断三条边能否构成三角形,若能构成三角形,则继续判断能否构成等腰三角形,等边三角形。 任意两边之和大于第三边才能构成三角形, 等腰三角形:至少有两条边相等的三角形 等边三角形:三条边都相等的三角形 输入格式 一行,三个正整数 a , b , c a,b,c 依次表示三条边的长度。 输出格式 输出对应的判断结果: 若能构成三角形,单独使用一行输出“三角形” 若能构成等腰三角形,单独使用一行输出“等腰三角形” 若能构成等边三角形,单独使用一行输出“等边三角形” 若无法构成三角形,输出 “No” input1 复制 3 3 3 output1 复制 三角形 等腰三角形 等边三角形 input2 复制 3 3 5 output2 复制 三角形 等腰三角形 input3 复制 1 2 3 output3 复制 No 语言方向:C++ 系统环境:Windows(214点数解答 | 2025-08-24 17:31:55)86
- 题目描述 现有一个正整数 n n 请判断 n n 是否为 3 , 5 , 7 3,5,7 的倍数 输入格式 一行,一个正整数 n n。 输出格式 判断 n n 是否为 3 , 5 , 7 3,5,7 的倍数,若是则输出对应的数字,否则不输出,注意输出时,如果有多个满足的数字,数字之间需要使用一个英文逗号间隔 input1 复制 9 output1 复制 3 input2 复制 70 output2 复制 5,7 input2 复制 210 output2 复制 3,5,7 语言方向:C++ 系统环境:Windows(185点数解答 | 2025-08-24 18:42:18)71
- 阅读代码完成填空1~7题 import numpy as np # 生成 1000 个服从正态分布的随机整数(均值 100,标准差 8) np.random.seed(42) num1 = np.random.normal( ______, 8, size=1000).reshape(-1,1). ______ #第1、2空 # 生成 1000 个 1 到 10 之间的随机整数 num2 = np.random.randint(1, ______, size=1000).reshape(-1,1) #第3空 # 合并数据 data = np.__________((num1, num2), axis=_________) #第4、5空 # 保存到 CSV 文件,数据间以逗号间隔,保存格式为整数%d np.savetxt("data.csv", data, delimiter="_________", fmt='%d',header="num1,num2", comments="") #第6空 # 读取 CSV 文(506点数解答 | 2025-03-23 14:32:14)205
- 阅读代码完成填空1~7题 import numpy as np # 生成 1000 个服从正态分布的随机整数(均值 100,标准差 8) np.random.seed(42) num1 = np.random.normal( ______, 8, size=1000).reshape(-1,1). ______ #第1、2空 # 生成 1000 个 1 到 10 之间的随机整数 num2 = np.random.randint(1, ______, size=1000).reshape(-1,1) #第3空 # 合并数据 data = np.__________((num1, num2), axis=_________) #第4、5空 # 保存到 CSV 文件,数据间以逗号间隔,保存格式为整数%d np.savetxt("data.csv", data, delimiter="_________", fmt='%d',header="num1,num2", comments="") #第6空 # 读取 CSV 文(116点数解答 | 2025-03-26 22:22:15)228
- 阅读代码完成填空1~7题 import numpy as np # 生成 1000 个服从正态分布的随机整数(均值 100,标准差 8) np.random.seed(42) num1 = np.random.normal( ______, 8, size=1000).reshape(-1,1). ______ #第1、2空 # 生成 1000 个 1 到 10 之间的随机整数 num2 = np.random.randint(1, ______, size=1000).reshape(-1,1) #第3空 # 合并数据 data = np.__________((num1, num2), axis=_________) #第4、5空 # 保存到 CSV 文件,数据间以逗号间隔,保存格式为整数%d np.savetxt("data.csv", data, delimiter="_________", fmt='%d',header="num1,num2", comments="") #第6空 # 读取 CSV 文(178点数解答 | 2025-03-26 22:26:30)271
- 题目描述 输入 n n 个整数,输出这 n n 个数字之和。 输入格式 输入包括两行。 第一行包含一个整数 n n,表示存在 n n 个整数。 第二行包含 n n 个整数,第 i i 个数字为 a i a i ,数字之间用空格隔开。 输出格式 输出包括一行,为 n n 个数字之和。 input1 复制 3 1 2 3 output1 复制 6 input2 复制 4 3 1 4 1 output2 复制 9(192点数解答 | 2025-06-14 09:50:20)198
- 题目描述 输入 n n 个整数,输出这 n n 个数字之和。 输入格式 输入包括两行。 第一行包含一个整数 n n,表示存在 n n 个整数。 第二行包含 n n 个整数,第 i i 个数字为 a i a i ,数字之间用空格隔开。 输出格式 输出包括一行,为 n n 个数字之和。 input1 复制 3 1 2 3 output1 复制 6 input2 复制 4 3 1 4 1 output2 复制 9 c++(248点数解答 | 2025-06-14 09:51:28)92
- 题目描述 输入三个整数 x , y , z x,y,z, 如果 x x为奇数,输出 1 ∼ y 1∼y之间的所有数,如果 x x为偶数,输出 1 ∼ z 1∼z之间的所有数。 输入格式 输入包括一行,包含三个整数 x , y , z x,y,z,数字之间用空格隔开。 输出格式 输出包括一行 如果 x x为奇数,输出 1 ∼ y 1∼y之间的所有数,如果 x x为偶数,输出 1 ∼ z 1∼z之间的所有数,输出时,数与数之间用1个空格隔开。 input1 复制 1 10 5 output1 复制 1 2 3 4 5 6 7 8 9 10 input2 复制 4 20 4 output2 复制 1 2 3 4 样例解释 对于样例 1 1: x x是奇数, y = 10 y=10,因此输出 1 ∼ 10 1∼10。 对于样例 2 2: x x是偶数, z = 10 z=10,因此输出 1 ∼ 4 1∼4 。 c++ (391点数解答 | 2025-06-14 09:57:45)172
- 题目描述 输入两个整数 a , b a,b 1. 1. 对 a , b a,b之间个位数是 3 3的数字求和并输出。 2. 2. 判断这个和是不是3的倍数,如果这个数字是3的倍数,请输出: Y E S YES,否则的话输出: N O NO。 输入格式 输入包括一行,包含两个整数 a , b a,b,数字之间用空格隔开。 输出格式 输出包括两行 第一行为 a ∼ b a∼b 之间 个位数是 3 3 的数字和。 第二行 如果这个数字是3的倍数,请输出: Y E S YES,否则的话输出: N O NO。 input1 复制 1 10 output1 复制 3 YES input2 复制 4 21 output2 复制 13 NO 样例解释 对于样例 1 1: 1 ∼ 10 1∼10 之间个位数是 3 3数字有 1 1 个,是 3 3,所以第一行输出 3 3,它是 3 3的倍数,所以第二行输出: Y E S YES。 对于样例 2 2: 4 ∼ 21 4∼21 之间个位数是 3 3数字有 1 1 个,是 13 13,所以第一行输出 13 13,它不是 3 3(358点数解答 | 2025-07-12 21:48:22)115
- 题目描述 输入四个整数 x , y , a , b x,y,a,b,请你按照要求输出 x ∼ y x∼y 之间的所有数。 要求: 不要输出数字 a a。 不要输出大于等于数字 b b 的数。 输入格式 输入包括一行,包含四个整数 x , y , a , b x,y,a,b,数字之间用空格隔开。 输出格式 输出包括一行,为 x ∼ y x∼y 之间符合要求的数字。 input1 复制 10 20 13 17 output1 复制 10 11 12 14 15 16 input2 复制 50 55 52 100 output2 复制 50 51 53 54 55 样例解释 对于样例 1 1: 样例要求输出 10 ∼ 20 10∼20 之间不是 13 13, 且小于 17 17 的数,故有 10 , 11 , 12 , 14 , 15 , 16 10,11,12,14,15,16。 数据规模与约定 对于 100 % 100% 的数据, 1 ≤ x ≤ y ≤ 100 1≤x≤y≤100, x ≤ a ≤ y x≤a≤y, x ≤ b x≤b。 C++程序(138点数解答 | 2025-07-19 20:44:46)187
- 题目描述 请从小到大输出 1 ~ n n 中所有个位为 5 5 或者个位为 8 8 的整数,每行 1 1 个。 输入格式 一行,一个正整数 n n。 输出格式 若干行,每行一个正整数,即 1 ~ n n 中所有满足条件的数。 input1 复制 20 output1 复制 5 8 15 18 input2 复制 30 output2 复制 5 8 15 18 25 28 数据规模与约定 对于 100 % 100% 的数据, 1 < n ≤ 10000 1<n≤10000。 语言: *********101112131415 在线(439点数解答 | 2025-07-20 15:05:34)110