How seantsao00/challenge2024 works
Project type and purpose
• From the README (“教學用遊戲原始碼”) and the file tree (main.py, model/, view/, controller/, ai/, event_manager/, instances_manager.py, image/, music/…), this is a standalone Python-based teaching game engine (“幻影的競技場”) used in CSIE Camp 2024. It follows an interactive game loop, driving model updates, rendering views, handling input and AI, and playing audio.
File structure
• Top-level orchestration:
• main.py — entry point, initializes and runs the game loop
• instances_manager.py — manages creation/updating of game object instances
• api/ — internal and prototype interfaces for higher-level logic or extensions
• event_manager/ — centralized event definition and dispatch
• controller/ — user input abstraction
• model/ — core game state (entities, bullets, buildings, map, teams, pathfinding, timers, results)
• view/ — rendering layer (screen info, object classes for animation, UI components, particles, etc.)
• ai/ — individual AI strategy scripts for bots
• const/ — configuration constants for all subsystems (entities, music, chat, visuals, grid)
• image/, music/, font/, topography/ — static assets loaded at runtime
• tool/ — asset-preprocessing scripts (PNG tools, map generation, keyboard config)
• pyproject.toml, requirements.txt — build and dependency info
README for additional insights
• The project uses Python 3.11, PEP8 style, virtual environment, and standard Python packaging. No explicit external services—pure local.
Main components and their interactions
a. Components
• Game Loop (main.py)
• Input Controller (controller/controller.py)
• Event Manager (event_manager/)
• Model (model/)
• Instances Manager
• AI Engine (ai/*.py)
• View Renderer (view/)
• Audio Manager (music/music.py)
• Configuration (const/)
• Asset Loaders (image/, font/, topography/)
• API Layer (api/) for internal extensions or prototyping
b. Relationships
1. main.py initializes Config (const/) and Assets (image/, music/, font/, topography/)
2. main.py sets up EventManager, Controller, InstancesManager, AI modules, Model, View, Audio
3. Each tick of the Game Loop:
– Controller reads hardware/input events → dispatches into EventManager
– EventManager routes events to Model or AI
– AI modules subscribe to model state or events, compute next moves, feed them back as Events
– Model processes events: updates Entities, Bullets, Buildings, PathFinder, Timers, TeamVision
– InstancesManager instantiates or recycles game objects in memory
– View subscribes to Model changes or polls Model state to render via view.object classes
– Audio Manager plays background music and effects based on Model events
4. API Layer can be used by higher-level logic, test harnesses, or prototype features to manipulate Model/Events
c. Architectural patterns and principles
• MVC (Model–View–Controller) with an explicit Event Dispatcher
• Separation of concerns:
– controller/ for input abstraction
– model/ for game state and rules
– view/ for rendering and UI
• Plugin-style AI: multiple .py scripts implementing a common interface, dynamically loaded
• Centralized configuration via const/ modules
• Asset pipeline isolated in tool/ and loaded at runtime
• InstancesManager to enforce object lifecycle and pooling
d. Key technologies and libraries
• Python 3.11
• Likely Pygame or similar rendering library (inferred from view/ modules)
• JSON/CSV for topography definitions
• Standard Python packaging (pyproject.toml, requirements.txt)
Diagramming recommendations
• Orange for tooling (tool/)
• Input → Controller → EventManager → Model
• Model → InstancesManager / Model → View / Model → Audio
• AI ↔ EventManager ↔ Model
• Assets/config → relevant subsystems
• Main game loop flow around main.py
Essential elements
• Asset/config clusters: const/, image/, music/, topography/
• Tooling: tool/ (outside runtime)