From f8fb4a7db943f476721a87af70022b2d5f0eaac6 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 30 Mar 2026 17:13:17 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Improve=20score=20rea?= =?UTF-8?q?dability=20and=20game-over=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added `formatWithCommas` helper for thousands-separator formatting of scores. - Improved live score display with `\033[K` (Erase in Line) for cleaner UI updates. - Enhanced Game Over screen to display the previous personal best for better achievement context. - Verified terminal cursor handling with `verify_ux.py`. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- .Jules/palette.md | 4 ++++ src/main.cpp | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/.Jules/palette.md b/.Jules/palette.md index 853ef9c..441497f 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -29,3 +29,7 @@ ## 2025-01-24 - Real-time Achievement Feedback in CLI **Learning:** In terminal-based games, displaying achievement progress (like a live high score) in real-time provides immediate tactile reward and engagement. Furthermore, inclusive UX means ensuring first-time players also receive "New Best" feedback, even when their initial record is zero. **Action:** Update session-high-score variables immediately upon record-breaking and display them in the live HUD. Ensure achievement conditions (`score > highscore`) don't exclude the first-time user experience. + +## 2026-03-30 - Enhanced Feedback & Readability in CLI +**Learning:** Large numbers in CLI are hard to read without thousands separators. Using \033[K (Erase in Line) is superior to space-padding for clean UI updates. Providing the previous record for comparison on the game-over screen enhances the user's sense of achievement. +**Action:** Use formatWithCommas for all large numeric displays and \033[K for in-place line updates. Always show 'before and after' context for achievements. diff --git a/src/main.cpp b/src/main.cpp index af692c8..32ccc2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,16 @@ void restore_terminal(int signum) { _exit(signum); } +std::string formatWithCommas(long long value) { + std::string res = std::to_string(value); + int pos = res.length() - 3; + while (pos > 0) { + res.insert(pos, ","); + pos -= 3; + } + return res; +} + long long load_highscore() { long long highscore = 0; std::ifstream file("highscore.txt"); @@ -77,7 +87,7 @@ int main() { std::cout << CLR_CTRL << "==========================\n SPEED CLICKER\n==========================\n" << CLR_RESET; if (highscore > 0) { - std::cout << " Personal Best: " << CLR_SCORE << highscore << CLR_RESET << "\n\n"; + std::cout << " Personal Best: " << CLR_SCORE << formatWithCommas(highscore) << CLR_RESET << "\n\n"; } std::cout << "Controls:\n " << CLR_CTRL << "[h]" << CLR_RESET << " Toggle Hard Mode (10x Speed!)\n " @@ -141,10 +151,10 @@ int main() { } if (updateUI) { - std::cout << "\r" << CLR_SCORE << "Score: " << score << CLR_RESET << " | High: " << highscore << " " + std::cout << "\r" << CLR_SCORE << "Score: " << formatWithCommas(score) << CLR_RESET << " | High: " << formatWithCommas(highscore) << " " << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") << (score > initialHighscore ? " NEW BEST! 🥳" : "") - << " " << std::flush; + << "\033[K" << CLR_RESET << std::flush; updateUI = false; } } @@ -154,9 +164,12 @@ int main() { } tcsetattr(STDIN_FILENO, TCSANOW, &oldt); - std::cout << "\n\n" << CLR_SCORE << "Final Score: " << score << CLR_RESET << "\n"; + std::cout << "\n\n" << CLR_SCORE << "Final Score: " << formatWithCommas(score) << CLR_RESET << "\n"; if (score > initialHighscore) { std::cout << "Congratulations! A new personal best!\n"; + if (initialHighscore > 0) { + std::cout << "You beat your previous best of " << CLR_SCORE << formatWithCommas(initialHighscore) << CLR_RESET << "!\n"; + } } std::cout << "Thanks for playing!\n"; std::cout << "\033[?25h" << std::flush;