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
英文地址,請注明出處:http://en.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…