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>
47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
"""Run the Snake game client."""
|
|
|
|
import asyncio
|
|
import argparse
|
|
from src.client.game_client import main
|
|
from src.shared.constants import DEFAULT_PORT
|
|
|
|
|
|
async def run_client() -> None:
|
|
"""Run the client with command line arguments."""
|
|
parser = argparse.ArgumentParser(description="Run the Snake game client")
|
|
parser.add_argument(
|
|
"host",
|
|
nargs="?",
|
|
default=None,
|
|
help="Server host address (omit to use auto-discovery)",
|
|
)
|
|
parser.add_argument(
|
|
"--port",
|
|
type=int,
|
|
default=DEFAULT_PORT,
|
|
help=f"Server port number (default: {DEFAULT_PORT})",
|
|
)
|
|
parser.add_argument(
|
|
"--name",
|
|
default="Player",
|
|
help="Your player name (default: Player)",
|
|
)
|
|
parser.add_argument(
|
|
"--discover",
|
|
action="store_true",
|
|
help="Force server discovery even if host is specified",
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
await main(
|
|
host=args.host,
|
|
port=args.port,
|
|
name=args.name,
|
|
discover=args.discover,
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(run_client())
|