feat: add single player snake mode
Add solo mode where players survive as long as possible while tracking score (food eaten). Single player games start with a shorter 3-second countdown vs 10 seconds for multiplayer, maintain exactly 1 food item for classic snake feel, and end when the player dies rather than when one player remains. - Add GameMode type (ModeMultiplayer/ModeSinglePlayer) and Score field - Filter single player games from "Join a Game" lobby list - Show "Ready?" and "Score: X" UI for single player mode - Hide invite link for single player games - Preserve game mode on rematch
This commit is contained in:
@@ -152,8 +152,12 @@ func RemoveFood(state *GameState, indices []int) {
|
||||
}
|
||||
|
||||
// SpawnFood adds food items to maintain the target count.
|
||||
func SpawnFood(state *GameState, playerCount int) {
|
||||
// Single player always maintains exactly 1 food for classic snake feel.
|
||||
func SpawnFood(state *GameState, playerCount int, mode GameMode) {
|
||||
target := playerCount/2 + 1
|
||||
if mode == ModeSinglePlayer {
|
||||
target = 1
|
||||
}
|
||||
for len(state.Food) < target {
|
||||
p := randomEmptyCell(state)
|
||||
if p == nil {
|
||||
|
||||
Reference in New Issue
Block a user