Add player names to snake display
Show human-readable player names instead of player IDs in both desktop and web clients. Player names are now stored in the Snake model and synchronized across all clients. Changes: - Added player_name field to Snake model - Updated create_snake() to accept player_name parameter - Desktop client shows "YOU:" or "PlayerName:" - Web client shows "You (Name)" or "Name" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -34,6 +34,7 @@ class Snake:
|
||||
score: int = 0
|
||||
stuck: bool = False # True when snake is blocked and shrinking
|
||||
color_index: int = 0 # Index in COLOR_SNAKES array for persistent color
|
||||
player_name: str = "" # Human-readable player name
|
||||
|
||||
def get_head(self) -> Position:
|
||||
"""Get the head position of the snake."""
|
||||
@@ -49,6 +50,7 @@ class Snake:
|
||||
"score": self.score,
|
||||
"stuck": self.stuck,
|
||||
"color_index": self.color_index,
|
||||
"player_name": self.player_name,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
@@ -61,6 +63,7 @@ class Snake:
|
||||
snake.score = data["score"]
|
||||
snake.stuck = data.get("stuck", False) # Default to False for backward compatibility
|
||||
snake.color_index = data.get("color_index", 0) # Default to 0 for backward compatibility
|
||||
snake.player_name = data.get("player_name", "") # Default to empty string for backward compatibility
|
||||
return snake
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user