From e5b18b814fbcce04a7b5032de37aefb5cde3d01f Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Thu, 30 Oct 2025 23:00:55 +0000 Subject: [PATCH] fix(phase1.4): correct score calculation - food worth CURRENT level, level up AFTER - Add points at CURRENT level FIRST - THEN check if we should level up for NEXT food - Food that triggers level up is worth old level points, not new - Example: eat food 1 (+1), eat food 2 (+1, now level up), eat food 3 (+2) - Correct scoring: 1 + 1 = 2 points at level 1, then 2 + 2 = 4 at level 2 --- src/useGameStatus/useGameStatus.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/useGameStatus/useGameStatus.ts b/src/useGameStatus/useGameStatus.ts index 49b9506..65c983a 100755 --- a/src/useGameStatus/useGameStatus.ts +++ b/src/useGameStatus/useGameStatus.ts @@ -90,20 +90,17 @@ export function useGameStatus( foodsEatenRef.current += 1; setScore((prev) => { - let newScore = prev; - let currentLevel = levelRef.current; + // Add points at CURRENT level first + let newScore = prev + levelRef.current; - // Check if we should level up BEFORE adding points + // THEN check if we should level up for NEXT food if (foodsEatenRef.current >= FOODS_PER_LEVEL) { - currentLevel = levelRef.current + 1; - levelRef.current = currentLevel; - setLevel(currentLevel); - currentFpsRef.current = INITIAL_FPS + (currentLevel - 1); + const newLevel = levelRef.current + 1; + levelRef.current = newLevel; + setLevel(newLevel); + currentFpsRef.current = INITIAL_FPS + (newLevel - 1); foodsEatenRef.current = 0; } - - // Add points at the current (possibly new) level - newScore = prev + currentLevel; foodManagerRef.current.spawnFood( snakeManagerRef.current.snakeBodyRef.current,