From b60d17e2c8888352a2053f00915339f3ca42c138 Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Thu, 30 Oct 2025 23:12:51 +0000 Subject: [PATCH] refactor(phase1.4): clean up debug logging and finalize score calculation - Remove all console.log debug statements - Score calculation now working correctly: * Each food worth current level points * Level up happens AFTER food is eaten and scored * Example: food1(+1)=1pt, food2(+1, lvlup)=2pts, food3(+2)=4pts - FOODS_PER_LEVEL = 2 (final production setting) - Code is clean and production-ready --- src/useGameStatus/useGameStatus.ts | 35 +++++++++++++----------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/useGameStatus/useGameStatus.ts b/src/useGameStatus/useGameStatus.ts index c847921..7fb77b3 100755 --- a/src/useGameStatus/useGameStatus.ts +++ b/src/useGameStatus/useGameStatus.ts @@ -90,28 +90,23 @@ export function useGameStatus( // Check BEFORE incrementing if we're about to level up const willLevelUp = (foodsEatenRef.current + 1) >= FOODS_PER_LEVEL; - foodsEatenRef.current += 1; + foodsEatenRef.current += 1; - console.log(`[FOOD] Eaten: ${foodsEatenRef.current}, Will Level Up: ${willLevelUp}, Current Level: ${levelRef.current}`); + // Save the current level BEFORE any changes + const pointsToAdd = levelRef.current; + + // Update level OUTSIDE of setScore to avoid multiple triggers + if (willLevelUp) { + const newLevel = levelRef.current + 1; + levelRef.current = newLevel; + setLevel(newLevel); + currentFpsRef.current = INITIAL_FPS + (newLevel - 1); + foodsEatenRef.current = 0; + } - // Save the current level BEFORE any changes - const pointsToAdd = levelRef.current; - - // Update level OUTSIDE of setScore to avoid multiple triggers - if (willLevelUp) { - const newLevel = levelRef.current + 1; - levelRef.current = newLevel; - setLevel(newLevel); - currentFpsRef.current = INITIAL_FPS + (newLevel - 1); - foodsEatenRef.current = 0; - console.log(`[LEVELUP] New Level: ${newLevel}`); - } - - setScore((prev) => { - // Add points at CURRENT level - let newScore = prev + pointsToAdd; - - console.log(`[SCORE] Adding ${pointsToAdd} points, Total: ${newScore}`); + setScore((prev) => { + // Add points at CURRENT level + let newScore = prev + pointsToAdd; foodManagerRef.current.spawnFood( snakeManagerRef.current.snakeBodyRef.current,