Pygame模块化实战:火星救援游戏开发指南

Pygame模块化实战:火星救援游戏开发指南

用Python打造太空探险游戏,掌握模块化开发核心技巧

一、火星救援:模块化开发的完美场景

​想象这样的场景​​:
你是一名宇航员,被困在火星表面,需要收集资源、修复飞船、躲避沙尘暴,最终逃离这颗红色星球。这正是我们将要开发的游戏!

二、模块化设计:游戏开发的架构艺术

1. 模块化架构图

2. 模块化开发优势

  1. ​并行开发​​:团队可同时开发不同模块
  2. ​易于维护​​:修复问题只需修改单个模块
  3. ​代码复用​​:模块可在不同项目中重用
  4. ​可扩展性​​:轻松添加新功能模块

三、核心模块实现:火星救援游戏引擎

1. 游戏初始化模块

import pygame
import sys
import random
import mathclass Game:"""游戏主控制器"""def __init__(self, width=800, height=600):pygame.init()self.screen = pygame.display.set_mode((width, height))pygame.display.set_caption("火星救援")self.clock = pygame.time.Clock()self.running = Trueself.game_state = "menu"  # menu, playing, paused, game_over# 模块初始化self.player = Player(self)self.environment = Environment(self)self.resource_manager = ResourceManager(self)self.mission_control = MissionControl(self)self.ui = UI(self)def run(self):"""游戏主循环"""while self.running:self.handle_events()self.update()self.render()self.clock.tick(60)pygame.quit()sys.exit()def handle_events(self):"""处理事件"""for event in pygame.event.get():if event.type == pygame.QUIT:self.running = False# 分发事件到各模块self.player.handle_event(event)self.ui.handle_event(event)def update(self):"""更新游戏状态"""if self.game_state == "playing":self.player.update()self.environment.update()self.resource_manager.update()self.mission_control.update()def render(self):"""渲染游戏画面"""self.screen.fill((0, 0, 0))  # 黑色背景# 渲染各模块self.environment.render(self.screen)self.player.render(self.screen)self.resource_manager.render(self.screen)self.ui.render(self.screen)pygame.display.flip()# 启动游戏
if __name__ == "__main__":game = Game()game.run()

2. 玩家模块:火星宇航员

class Player:"""玩家角色模块"""def __init__(self, game):self.game = gameself.image = pygame.Surface((30, 50))self.image.fill((255, 0, 0))  # 红色宇航服self.rect = self.image.get_rect(center=(400, 300))self.speed = 5self.oxygen = 100  # 氧气值self.health = 100  # 生命值self.inventory = {}  # 背包def handle_event(self, event):"""处理玩家输入"""if event.type == pygame.KEYDOWN:if event.key == pygame.K_SPACE:self.collect_resource()def update(self):"""更新玩家状态"""# 移动控制keys = pygame.key.get_pressed()if keys[pygame.K_LEFT]:self.rect.x -= self.speedif keys[pygame.K_RIGHT]:self.rect.x += self.speedif keys[pygame.K_UP]:self.rect.y -= self.speedif keys[pygame.K_DOWN]:self.rect.y += self.speed# 边界检查self.rect.clamp_ip(self.game.screen.get_rect())# 氧气消耗self.oxygen -= 0.05if self.oxygen <= 0:self.health -= 1self.oxygen = 0# 生命值检查if self.health <= 0:self.game.game_state = "game_over"def collect_resource(self):"""收集资源"""for resource in self.game.resource_manager.resources:if self.rect.colliderect(resource.rect):if resource.type in self.inventory:self.inventory[resource.type] += 1else:self.inventory[resource.type] = 1self.game.resource_manager.resources.remove(resource)breakdef render(self, surface):"""渲染玩家"""surface.blit(self.image, self.rect)# 显示氧气和生命值pygame.draw.rect(surface, (0, 100, 200), (10, 10, self.oxygen, 20))pygame.draw.rect(surface, (200, 0, 0), (10, 40, self.health, 20))

3. 环境模块:火星地表

class Environment:"""火星环境模块"""def __init__(self, game):self.game = gameself.terrain = self.generate_terrain()self.weather = "clear"  # clear, dust_storm, solar_flareself.weather_timer = 0self.weather_duration = 0def generate_terrain(self):"""生成火星地形"""terrain = []# 创建一些随机岩石for _ in range(20):x = random.randint(0, self.game.screen.get_width())y = random.randint(0, self.game.screen.get_height())size = random.randint(20, 50)terrain.append({"type": "rock", "pos": (x, y), "size": size})return terraindef update(self):"""更新环境状态"""# 天气变化self.weather_timer += 1if self.weather_timer > self.weather_duration:self.change_weather()# 天气影响if self.weather == "dust_storm":self.game.player.oxygen -= 0.1  # 沙尘暴加速氧气消耗elif self.weather == "solar_flare":self.game.player.health -= 0.05  # 太阳耀斑伤害def change_weather(self):"""随机改变天气"""weather_types = ["clear", "dust_storm", "solar_flare"]self.weather = random.choice(weather_types)self.weather_duration = random.randint(300, 900)  # 5-15秒self.weather_timer = 0def render(self, surface):"""渲染环境"""# 绘制火星表面surface.fill((150, 75, 0))  # 火星红# 绘制地形for feature in self.terrain:if feature["type"] == "rock":pygame.draw.circle(surface, (100, 50, 0), feature["pos"], feature["size"])# 天气效果if self.weather == "dust_storm":# 半透明黄色层模拟沙尘dust = pygame.Surface(self.game.screen.get_size())dust.fill((200, 180, 50))dust.set_alpha(100)surface.blit(dust, (0, 0))elif self.weather == "solar_flare":# 闪烁效果模拟太阳耀斑if pygame.time.get_ticks() % 500 < 250:flare = pygame.Surface(self.game.screen.get_size())flare.fill((255, 255, 200))flare.set_alpha(150)surface.blit(flare, (0, 0))

4. 资源模块:火星物资

class Resource:"""资源类"""def __init__(self, game, resource_type, position):self.game = gameself.type = resource_typeself.position = positionself.size = 20# 创建资源图像self.image = pygame.Surface((self.size, self.size))# 不同资源不同颜色colors = {"oxygen": (0, 100, 255),"water": (0, 0, 255),"metal": (150, 150, 150),"electronics": (255, 255, 0),"food": (0, 255, 0)}self.image.fill(colors.get(resource_type, (255, 0, 255)))self.rect = self.image.get_rect(center=position)def render(self, surface):"""渲染资源"""surface.blit(self.image, self.rect)class ResourceManager:"""资源管理模块"""def __init__(self, game):self.game = gameself.resources = []self.respawn_timer = 0self.generate_initial_resources()def generate_initial_resources(self):"""生成初始资源"""resource_types = ["oxygen", "water", "metal", "electronics", "food"]for _ in range(15):resource_type = random.choice(resource_types)x = random.randint(50, self.game.screen.get_width() - 50)y = random.randint(50, self.game.screen.get_height() - 50)self.resources.append(Resource(self.game, resource_type, (x, y)))def update(self):"""更新资源状态"""# 资源重生self.respawn_timer += 1if self.respawn_timer > 300:  # 每5秒重生一个资源self.respawn_resource()self.respawn_timer = 0def respawn_resource(self):"""重生一个新资源"""if len(self.resources) < 20:  # 限制最大资源数量resource_types = ["oxygen", "water", "metal", "electronics", "food"]resource_type = random.choice(resource_types)x = random.randint(50, self.game.screen.get_width() - 50)y = random.randint(50, self.game.screen.get_height() - 50)self.resources.append(Resource(self.game, resource_type, (x, y)))def render(self, surface):"""渲染所有资源"""for resource in self.resources:resource.render(surface)

5. 任务模块:逃离火星

class Mission:"""任务类"""def __init__(self, title, description, objective, reward):self.title = titleself.description = descriptionself.objective = objective  # {"resource": amount} 或 {"action": count}self.reward = rewardself.completed = Falseself.progress = 0def update_progress(self, game):"""更新任务进度"""if not self.completed:# 检查资源收集任务if isinstance(self.objective, dict):for resource, amount in self.objective.items():if resource in game.player.inventory:self.progress = min(amount, game.player.inventory[resource])# 检查是否完成if self.progress >= sum(self.objective.values()):self.completed = Trueself.apply_reward(game)def apply_reward(self, game):"""应用任务奖励"""if "oxygen" in self.reward:game.player.oxygen = min(100, game.player.oxygen + self.reward["oxygen"])if "health" in self.reward:game.player.health = min(100, game.player.health + self.reward["health"])class MissionControl:"""任务管理模块"""def __init__(self, game):self.game = gameself.missions = [Mission("寻找氧气", "收集3个氧气罐维持生命", {"oxygen": 3}, {"oxygen": 20}),Mission("收集金属", "收集5个金属碎片修复飞船", {"metal": 5}, {"health": 10}),Mission("修复电子系统", "找到3个电子元件修复通讯系统", {"electronics": 3}, {"oxygen": 30, "health": 20})]self.current_mission_index = 0@propertydef current_mission(self):"""获取当前任务"""if self.current_mission_index < len(self.missions):return self.missions[self.current_mission_index]return Nonedef update(self):"""更新任务状态"""if self.current_mission:self.current_mission.update_progress(self.game)# 检查任务完成if self.current_mission.completed:self.current_mission_index += 1# 所有任务完成,游戏胜利if self.current_mission_index >= len(self.missions):self.game.game_state = "victory"def render(self, surface):"""渲染任务信息"""if self.current_mission:font = pygame.font.SysFont(None, 24)# 任务标题title_text = font.render(f"任务: {self.current_mission.title}", True, (255, 255, 255))surface.blit(title_text, (10, 70))# 任务描述desc_text = font.render(self.current_mission.description, True, (200, 200, 200))surface.blit(desc_text, (10, 100))# 任务进度if isinstance(self.current_mission.objective, dict):progress_text = []for resource, amount in self.current_mission.objective.items():progress = self.current_mission.progresstext = f"{resource}: {progress}/{amount}"progress_text.append(text)progress_str = "  ".join(progress_text)progress_render = font.render(progress_str, True, (0, 255, 0))surface.blit(progress_render, (10, 130))

6. 界面模块:游戏HUD

class UI:"""用户界面模块"""def __init__(self, game):self.game = gameself.font = pygame.font.SysFont(None, 36)self.menu_items = ["开始游戏", "游戏设置", "退出游戏"]self.selected_item = 0def handle_event(self, event):"""处理界面事件"""if event.type == pygame.KEYDOWN:if self.game.game_state == "menu":if event.key == pygame.K_UP:self.selected_item = (self.selected_item - 1) % len(self.menu_items)elif event.key == pygame.K_DOWN:self.selected_item = (self.selected_item + 1) % len(self.menu_items)elif event.key == pygame.K_RETURN:self.handle_menu_selection()def handle_menu_selection(self):"""处理菜单选择"""if self.menu_items[self.selected_item] == "开始游戏":self.game.game_state = "playing"elif self.menu_items[self.selected_item] == "退出游戏":self.game.running = Falsedef render(self, surface):"""渲染用户界面"""if self.game.game_state == "menu":self.render_menu(surface)elif self.game.game_state == "playing":self.render_hud(surface)elif self.game.game_state == "game_over":self.render_game_over(surface)elif self.game.game_state == "victory":self.render_victory(surface)def render_menu(self, surface):"""渲染主菜单"""title_font = pygame.font.SysFont(None, 72)title = title_font.render("火星救援", True, (255, 0, 0))surface.blit(title, (self.game.screen.get_width()//2 - title.get_width()//2, 100))for i, item in enumerate(self.menu_items):color = (0, 255, 0) if i == self.selected_item else (255, 255, 255)text = self.font.render(item, True, color)surface.blit(text, (self.game.screen.get_width()//2 - text.get_width()//2, 250 + i*50))def render_hud(self, surface):"""渲染游戏HUD"""# 氧气和生命值已在玩家模块渲染# 渲染任务信息self.game.mission_control.render(surface)# 渲染背包inventory_y = 160font = pygame.font.SysFont(None, 24)title = font.render("背包:", True, (255, 255, 255))surface.blit(title, (10, inventory_y))for i, (item, count) in enumerate(self.game.player.inventory.items()):text = font.render(f"{item}: {count}", True, (200, 200, 0))surface.blit(text, (20, inventory_y + 30 + i*25))def render_game_over(self, surface):"""渲染游戏结束画面"""overlay = pygame.Surface(self.game.screen.get_size())overlay.fill((0, 0, 0))overlay.set_alpha(180)surface.blit(overlay, (0, 0))font = pygame.font.SysFont(None, 72)text = font.render("任务失败", True, (255, 0, 0))surface.blit(text, (self.game.screen.get_width()//2 - text.get_width()//2, self.game.screen.get_height()//2 - text.get_height()//2))restart_font = pygame.font.SysFont(None, 36)restart = restart_font.render("按R键重新开始", True, (255, 255, 255))surface.blit(restart, (self.game.screen.get_width()//2 - restart.get_width()//2, self.game.screen.get_height()//2 + 50))def render_victory(self, surface):"""渲染胜利画面"""overlay = pygame.Surface(self.game.screen.get_size())overlay.fill((0, 50, 0))overlay.set_alpha(180)surface.blit(overlay, (0, 0))font = pygame.font.SysFont(None, 72)text = font.render("任务成功!", True, (0, 255, 0))surface.blit(text, (self.game.screen.get_width()//2 - text.get_width()//2, self.game.screen.get_height()//2 - text.get_height()//2))subtitle_font = pygame.font.SysFont(None, 36)subtitle = subtitle_font.render("你成功逃离了火星!", True, (200, 255, 200))surface.blit(subtitle, (self.game.screen.get_width()//2 - subtitle.get_width()//2, self.game.screen.get_height()//2 + 50))

四、模块化开发最佳实践

1. 模块通信模式

2. 模块化设计原则

  1. ​单一职责​​:每个模块只做一件事
  2. ​低耦合​​:模块间依赖最小化
  3. ​高内聚​​:模块内功能紧密相关
  4. ​接口清晰​​:定义明确的公共方法
  5. ​可替换性​​:模块可轻松替换实现

3. 常见错误与解决方案

​错误:模块依赖混乱​

# 反例:模块间直接访问内部属性
class Player:def update(self):# 错误:直接访问环境模块内部属性if self.game.environment.weather == "dust_storm":self.oxygen -= 0.1

​正解:使用接口方法​

# 正解:通过公共接口交互
class Environment:def get_weather_effect(self):"""获取天气影响"""effects = {"oxygen": 0, "health": 0}if self.weather == "dust_storm":effects["oxygen"] = -0.1return effectsclass Player:def update(self):# 通过公共接口获取影响effects = self.game.environment.get_weather_effect()self.oxygen += effects["oxygen"]

五、游戏优化:添加更多功能

1. 音效模块

class SoundManager:"""音效管理模块"""def __init__(self, game):self.game = gameself.sounds = {}# 加载音效self.load_sound("collect", "sounds/collect.wav")self.load_sound("storm", "sounds/dust_storm.wav")self.load_sound("victory", "sounds/victory.wav")def load_sound(self, name, path):"""加载音效文件"""try:self.sounds[name] = pygame.mixer.Sound(path)except:print(f"无法加载音效: {path}")def play(self, name):"""播放音效"""if name in self.sounds:self.sounds[name].play()def play_weather_sound(self):"""播放天气音效"""if self.game.environment.weather == "dust_storm":self.play("storm")

2. 存档系统

import json
import osclass SaveSystem:"""游戏存档模块"""SAVE_DIR = "saves"def __init__(self, game):self.game = gameos.makedirs(self.SAVE_DIR, exist_ok=True)def save_game(self, slot=1):"""保存游戏状态"""data = {"player": {"position": (self.game.player.rect.x, self.game.player.rect.y),"oxygen": self.game.player.oxygen,"health": self.game.player.health,"inventory": self.game.player.inventory},"environment": {"weather": self.game.environment.weather,"weather_timer": self.game.environment.weather_timer,"weather_duration": self.game.environment.weather_duration},"resources": [{"type": r.type, "position": r.position} for r in self.game.resource_manager.resources],"missions": {"current_index": self.game.mission_control.current_mission_index,"missions": [{"title": m.title,"progress": m.progress,"completed": m.completed} for m in self.game.mission_control.missions]}}with open(f"{self.SAVE_DIR}/save_{slot}.json", "w") as f:json.dump(data, f)def load_game(self, slot=1):"""加载游戏状态"""try:with open(f"{self.SAVE_DIR}/save_{slot}.json", "r") as f:data = json.load(f)# 恢复玩家状态player = self.game.playerplayer.rect.x, player.rect.y = data["player"]["position"]player.oxygen = data["player"]["oxygen"]player.health = data["player"]["health"]player.inventory = data["player"]["inventory"]# 恢复环境状态env = self.game.environmentenv.weather = data["environment"]["weather"]env.weather_timer = data["environment"]["weather_timer"]env.weather_duration = data["environment"]["weather_duration"]# 恢复资源self.game.resource_manager.resources = [Resource(self.game, r["type"], r["position"]) for r in data["resources"]]# 恢复任务mission_ctrl = self.game.mission_controlmission_ctrl.current_mission_index = data["missions"]["current_index"]for i, m_data in enumerate(data["missions"]["missions"]):mission_ctrl.missions[i].progress = m_data["progress"]mission_ctrl.missions[i].completed = m_data["completed"]return Trueexcept:return False

3. 粒子系统

class Particle:"""粒子类"""def __init__(self, position, velocity, color, size, lifetime):self.position = list(position)self.velocity = list(velocity)self.color = colorself.size = sizeself.lifetime = lifetimeself.age = 0def update(self):"""更新粒子状态"""self.position[0] += self.velocity[0]self.position[1] += self.velocity[1]self.age += 1return self.age < self.lifetimedef render(self, surface):"""渲染粒子"""alpha = 255 * (1 - self.age / self.lifetime)particle_surf = pygame.Surface((self.size, self.size), pygame.SRCALPHA)pygame.draw.circle(particle_surf, (*self.color, alpha), (self.size//2, self.size//2), self.size//2)surface.blit(particle_surf, (self.position[0] - self.size//2, self.position[1] - self.size//2))class ParticleSystem:"""粒子系统模块"""def __init__(self, game):self.game = gameself.particles = []def add_particles(self, position, count=10, color=(255, 255, 200), size_range=(2, 5), speed_range=(1, 3), lifetime=30):"""添加粒子"""for _ in range(count):angle = random.uniform(0, math.pi * 2)speed = random.uniform(*speed_range)velocity = (math.cos(angle) * speed, math.sin(angle) * speed)size = random.randint(*size_range)self.particles.append(Particle(position, velocity, color, size, lifetime))def update(self):"""更新所有粒子"""self.particles = [p for p in self.particles if p.update()]def render(self, surface):"""渲染所有粒子"""for particle in self.particles:particle.render(surface)

六、模块化开发思维:从游戏到工程

1. 模块化设计模式

2. 模块化开发工作流

3. 模块化开发工具链

  1. ​版本控制​​:Git + GitHub
  2. ​依赖管理​​:pip + requirements.txt
  3. ​文档生成​​:Sphinx + reStructuredText
  4. ​测试框架​​:pytest + unittest
  5. ​持续集成​​:GitHub Actions

七、结语:成为模块化开发大师

通过本指南,你已经掌握了:

  • 🧩 模块化设计原则
  • 🚀 Pygame游戏开发
  • 🪐 火星救援游戏实现
  • 🔧 模块通信机制
  • 🎮 游戏功能扩展技巧
  • 📦 模块化工程思维

​下一步行动​​:

  1. 运行完整火星救援游戏
  2. 添加更多模块(敌人系统、基地建设)
  3. 优化游戏画面(使用精灵图替代简单图形)
  4. 开发多人联机功能
  5. 将模块化思维应用到其他项目

"模块化开发不是技术,而是艺术。它让复杂系统变得简单,让不可能成为可能。"

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/web/90671.shtml
繁体地址,请注明出处:http://hk.pswp.cn/web/90671.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

三维图像识别中OpenCV、PCL和Open3D结合的主要技术概念、部分示例

文章目录1. 三维点云基础概念点云(Point Cloud)深度图像(Depth Image)体素(Voxel)2. 点云预处理技术去噪滤波(Noise Filtering)降采样(Downsampling)3. 特征提取与描述法向量估计(Normal Estimation)关键点检测(Keypoint Detection)特征描述子(Feature Descriptor)4. 点云配准(…

7.23数据结构——单链表

文章目录一、思维导图二、单链表代码head.htext.cmain.c现象一、思维导图 二、单链表代码 head.h #ifndef __HEAD_H__ #define __HEAD_H__#include <stdlib.h> #include <stdio.h> #include <string.h>enum A {FAULSE-1,//失败返回SUCCESS//成功返回};//给…

某种物联网SIM卡流量查询方法

说起流量卡,很多人可能还停留在营业厅办理的常规套餐里。但其实在 2016 年,三大运营商就推出了一种资费更为划算的正规流量卡 —— 物联卡。当年,当不少人还在用 50 元 1G 的流量时,第一批体验物联卡的用户已经享受到了 53 元 6G 的全国流量,彻底摆脱了流量焦虑。不过,至…

XTTS实现语音克隆:精确控制音频格式与生成流程【TTS的实战指南】

言简意赅的讲解XTTS解决的痛点 &#x1f4ce; 前置操作&#xff1a;如何使用 OBS Studio 录制高质量 WAV 语音&#xff08;建议先阅读并准备录音样本&#xff09; 本教程介绍如何使用 Coqui TTS 的 XTTS v2 模型 实现中文语音克隆&#xff0c;支持直接传入 .wav 文件&#xff0…

C/C++中常量放置在比较操作符左侧

目录 介绍 原因详解 避免误用赋值运算符 示例对比 结论 介绍 在编程中&#xff0c;将常量放在比较操作符&#xff08;如 或 !&#xff09;的左侧&#xff08;例如 if (42 value)&#xff09;&#xff0c;是一种被称为 "Yoda 条件"&#xff08;Yoda Conditions…

Node.js 模拟 Linux 环境

&#x1f9e9; 项目介绍 该项目使用 Node.js 实现了一个模拟的 Linux 终端环境&#xff0c;支持多种常见的 Linux 命令&#xff08;如 ls, cd, cat, mkdir, rm 等&#xff09;&#xff0c;所有文件操作都在内存中进行&#xff0c;并持久化到本地文件系统中。适合用于学习 Shel…

HAProxy 实验指南:从零开始搭建高可用负载均衡系统

引言HAProxy&#xff08;High Availability Proxy&#xff09;是一款高性能的TCP/HTTP负载均衡器和代理服务器&#xff0c;广泛用于构建高可用、可扩展的Web架构。它由法国开发者Willy Tarreau于2000年开发&#xff0c;如今已成为开源社区和企业级应用中不可或缺的工具。HAProx…

2.10DOM和BOM插入/移除/克隆

1.DOM创建/插入/移除/克隆1.1创建元素前面我们使用过 document.write 方法写入一个元素&#xff1a;这种方式写起来非常便捷&#xff0c;但是对于复杂的内容、元素关系拼接并不方便&#xff1b;它是在早期没有 DOM 的时候使用的方案&#xff0c;目前依然被保留了下来&#xff1…

华为仓颉编程语言的表达式及其特点

华为仓颉编程语言的表达式及其特点 仓颉&#xff08;Cangjie&#xff09;语言的表达式有一个明显的特点&#xff0c;范围不再局限于传统算术运算&#xff0c;而是扩展到条件表达式、循环表达式等多种类型&#xff0c;每种表达式均有确定的类型和值。 传统基本表达式&#xff0…

【linux】keepalived

一.高可用集群1.1 集群类型LB&#xff1a;Load Balance 负载均衡 LVS/HAProxy/nginx&#xff08;http/upstream, stream/upstream&#xff09; HA&#xff1a;High Availability 高可用集群 数据库、Redis SPoF: Single Point of Failure&#xff0c;解决单点故障 HPC&#xff…

Webpack配置原理

一、Loader&#xff1a; 1、定义&#xff1a;将不同类型的文件转换为 webpack 可识别的模块2、分类&#xff1a; ① pre&#xff1a; 前置 loader &#xff08;1&#xff09;配置&#xff1a;在 webpack 配置文件中通过enforce进行指定 loader的优先级配置&#xff08;2&#x…

对比JS“上下文”与“作用域”

下面从定义、特性、示例&#xff0c;以及在代码分析中何时侧重“上下文”&#xff08;Execution Context/this&#xff09;和何时侧重“作用域”&#xff08;Scope/变量查找&#xff09;&#xff0c;以及二者结合的场景来做对比和指导。一、概念对比 | 维度 | 上下文&#xff0…

如何做数据增强?

目录 1、为什么要做数据增强&#xff1f; 2、图像数据增强&#xff1f; 3、文本与音频数据增强&#xff1f; 4、高级数据增强&#xff1f; 数据增强技术就像是一种“造数据”的魔法&#xff0c;通过对原始数据进行各种变换&#xff0c;生成新的样本&#xff0c;从而提高模型…

Go by Example

网页地址Go by Example 中文版 Github仓库地址mmcgrana/gobyexample&#xff1a;按示例进行 HelloWorld package mainimport ("fmt" )func main() {fmt.Println("Hello World") } Hello World 值 package mainimport ("fmt" )func main() {…

ClickHouse高性能实时分析数据库-消费实时数据流(消费kafka)

告别等待&#xff0c;秒级响应&#xff01;这不只是教程&#xff0c;这是你驾驭PB级数据的超能力&#xff01;我的ClickHouse视频课&#xff0c;凝练十年实战精华&#xff0c;从入门到精通&#xff0c;从单机到集群。点开它&#xff0c;让数据处理速度快到飞起&#xff0c;让你…

电子电气架构 --- 车载软件与样件产品交付的方法

我是穿拖鞋的汉子,魔都中坚持长期主义的汽车电子工程师。 老规矩,分享一段喜欢的文字,避免自己成为高知识低文化的工程师: 简单,单纯,喜欢独处,独来独往,不易合同频过着接地气的生活,除了生存温饱问题之外,没有什么过多的欲望,表面看起来很高冷,内心热情,如果你身…

C++:STL中vector的使用和模拟实现

在上一篇中讲到了string类&#xff0c;string并不属于STL中因为string出现的比STL早&#xff0c;但是在使用方法上两者有相似之处&#xff0c;学习完string后再来看vector会容易的多&#xff0c;接着往下阅读&#xff0c;一定会有收获滴&#xff01; 目录 vector的介绍 vect…

仓库管理的流程、绩效和解决方案?

什么是仓库管理&#xff1f; 仓库管理涉及对所有仓库运营的日常监督。一个全面、集成的仓库管理解决方案采用行业最佳实践&#xff0c;并涵盖使高效运营得以实现的所有基本要素。这些要素包括分销和库存管理、仓库劳动力管理以及业务支持服务。此外&#xff0c;由内部提供或与服…

TIM 实现定时中断【STM32L4】【实操】

使用定时器实现定时中断的功能&#xff1a;比如每1ms进入中断处理函数使用STM32CubeMX配置TIM初始化先了解每个参数的含义&#xff0c;在进行配置Counter Settings: 计数器基本设置Prescaler(PSC): 预分频器&#xff0c;设置预分频器系数Counter Mode: 技术模式&#xff0c;…

Elasticsearch 的聚合(Aggregations)操作详解

目录 1. 概述 2. 聚合类型分类详解 2.1 桶聚合&#xff08;Bucket Aggregations&#xff09; 2.1.1 基础桶聚合 2.1.2 特殊桶聚合 2.1.3 高级桶聚合 2.2 指标聚合&#xff08;Metric Aggregations&#xff09; 2.2.1 单值指标聚合&#xff08;Single-value Metrics&am…