Initial commit: Multiplayer Snake game with server discovery

Implemented a complete network multiplayer Snake game with the following features:

Core Game:
- Client-server architecture using asyncio for networking
- Pygame-based rendering at 60 FPS
- Server-authoritative game state with 10 TPS
- Collision detection (walls, self, other players)
- Food spawning and score tracking
- Support for multiple players with color-coded snakes

Server Discovery:
- UDP multicast-based automatic server discovery (239.255.0.1:9999)
- Server beacon broadcasts presence every 2 seconds
- Client discovery with 3-second timeout
- Server selection UI for multiple servers
- Auto-connect for single server
- Graceful fallback to manual connection

Project Structure:
- src/shared/ - Protocol, models, constants, discovery utilities
- src/server/ - Game server, game logic, server beacon
- src/client/ - Game client, renderer, discovery, server selector
- tests/ - Unit tests for game logic, models, and discovery

Command-line interface with argparse for both server and client.
Comprehensive documentation in README.md and CLAUDE.md.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Vladyslav Doloman
2025-10-04 13:50:16 +03:00
commit 0703561446
28 changed files with 2523 additions and 0 deletions

48
src/shared/constants.py Normal file
View File

@@ -0,0 +1,48 @@
"""Game constants shared between client and server."""
# Network settings
DEFAULT_HOST = "localhost"
DEFAULT_PORT = 8888
# Multicast discovery settings
MULTICAST_GROUP = "239.255.0.1"
MULTICAST_PORT = 9999
DISCOVERY_TIMEOUT = 3.0 # seconds to wait for server responses
BEACON_INTERVAL = 2.0 # how often server announces itself
# Game grid settings
GRID_WIDTH = 40
GRID_HEIGHT = 30
CELL_SIZE = 20 # pixels
# Game timing
TICK_RATE = 0.1 # seconds (10 ticks per second)
FPS = 60 # client rendering FPS
# Game rules
INITIAL_SNAKE_LENGTH = 3
SNAKE_GROWTH = 1 # segments to grow when eating food
# Colors (RGB)
COLOR_BACKGROUND = (0, 0, 0)
COLOR_GRID = (40, 40, 40)
COLOR_FOOD = (255, 0, 0)
COLOR_SNAKES = [
(0, 255, 0), # Green - Player 1
(0, 0, 255), # Blue - Player 2
(255, 255, 0), # Yellow - Player 3
(255, 0, 255), # Magenta - Player 4
]
# Directions
UP = (0, -1)
DOWN = (0, 1)
LEFT = (-1, 0)
RIGHT = (1, 0)
OPPOSITE_DIRECTIONS = {
UP: DOWN,
DOWN: UP,
LEFT: RIGHT,
RIGHT: LEFT,
}