Major gameplay changes: - Snakes no longer die from collisions - When blocked, snakes get "stuck" - head stays in place, tail shrinks by 1 per tick - Snakes auto-unstick when obstacle clears (other snakes move/shrink away) - Minimum snake length is 1 (head-only) - Game runs continuously without rounds or game-over state Color system: - Each player gets a persistent color for their entire connection - Colors assigned on join, rotate through available colors - Color follows player even after disconnect/reconnect - Works for both desktop and web clients Display improvements: - Show snake length instead of score - Length accurately reflects current snake size - Updates in real-time as snakes grow/shrink Server fixes: - Fixed HTTP server initialization issues - Changed default host to 0.0.0.0 for network multiplayer - Improved file serving with proper routing Testing: - Updated all collision tests for stuck mechanics - Added tests for stuck/unstick behavior - Added tests for color persistence - All 12 tests passing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
51 lines
1.1 KiB
Python
51 lines
1.1 KiB
Python
"""Game constants shared between client and server."""
|
|
|
|
# Network settings
|
|
DEFAULT_HOST = "0.0.0.0" # Listen on all interfaces for multiplayer
|
|
DEFAULT_PORT = 8888
|
|
DEFAULT_WS_PORT = 8889
|
|
DEFAULT_HTTP_PORT = 8000
|
|
|
|
# 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,
|
|
}
|