From a174a4bcd4c3f02cea63ae4552b9c4e816da463f Mon Sep 17 00:00:00 2001 From: hefanyang Date: Wed, 20 May 2026 20:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BAclaude.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CLAUDE.md | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 CLAUDE.md diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..690461b --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,57 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Running the Game + +Use python env: C:\Users\Think1Admin\miniconda3\envs\play\python.exe + +```bash +# Install dependencies +pip install -r requirements.txt + +# Run (must use module form from project root) +python -m game.main +``` + +Requires Python 3.10+ with pygame >= 2.5. Developed with Python 3.12. + +## Architecture + +Classic Pygame main loop at 60 FPS in `game/main.py` (`Game` class). Update and draw pipelines are linear and sequential — no event bus or observer patterns. + +All game state lives on the `Game` instance as shared mutable lists: `enemies`, `towers`, `projectiles`, plus scalar state (`gold`, `lives`). Systems communicate by reading/writing these lists directly. + +### Update Order +``` +WaveManager.update → spawn enemies +Enemy.update → move along path, detect end-of-path +Tower.update → find targets, create Projectiles +Projectile.update → home in, deal damage (splash/slow on hit) +Reward collection + cleanup of dead entities +Win/loss check +``` + +### Draw Order +``` +Background → Map → Towers → Enemies → Projectiles → Placement preview → UI → Game-over overlay +``` + +## Key Design Patterns + +**Centralized config** — All constants, colors, tower/enemy stat tables, and path waypoints are in `game/config.py`. Balance tuning only requires editing this file and `WAVE_DATA` in `wave.py`. + +**Data-driven types** — Tower and enemy types are dictionaries (`TOWER_DATA`, `ENEMY_DATA`). Adding a new type requires: add dict entry in `config.py`, add draw code in the respective class, update wave data if it's an enemy, add button in `UI._init_tower_buttons()` if it's a tower. + +**Targeting** — Towers target by path progress (furthest-along enemy in range), not nearest distance. + +**Coordinate systems** — Pixel coords for rendering/movement; grid (col, row) for tower placement. `GameMap` handles conversion with `UI_TOP_HEIGHT` (40px) offset for the top status bar. + +**Procedural graphics** — All visuals drawn with `pygame.draw` calls. No sprite/image assets. + +## Extending the Game + +- **New tower**: Add to `TOWER_DATA` in config, draw shape in `Tower.draw()`, projectile visual in `Projectile.draw()`, button in `UI._init_tower_buttons()`. +- **New enemy**: Add to `ENEMY_DATA` in config, draw in `Enemy.draw()`, add to `WAVE_DATA` compositions. +- **New map**: Edit `PATH_WAYPOINTS` in config. Path cells recalculate automatically. +- **Balance**: All numeric tuning is in `config.py` constants.