From 4b779309e70a9689dc80423ea2738d0ab6c9509e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 14 Jul 2026 17:18:17 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Enhance=20score=20rea?= =?UTF-8?q?dability=20and=20achievement=20feedback?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented numeric comma formatting and improved achievement notifications. - Added `src/utils.hpp` with `formatWithCommas` utility. - Updated `src/main.cpp` to use comma formatting for all score displays. - Enhanced "NEW BEST" notifications with visual flair (✨) and contextual feedback (showing the previous high score). - Ensured proper color reset on the HUD line to prevent terminal bleed. Accessibility/UX: - Improved readability of large scores for better cognitive processing. - Provided immediate contextual feedback for achievements. - Enhanced visual prominence of personal best milestones. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- .Jules/palette.md | 4 ++++ src/main.cpp | 13 +++++++------ src/utils.hpp | 20 ++++++++++++++++++++ 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/utils.hpp diff --git a/.Jules/palette.md b/.Jules/palette.md index 05d4366..400bc4b 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -33,3 +33,7 @@ ## 2024-04-24 - Avoiding Trailing Artifacts in CLI Applications **Learning:** When dynamically updating terminal lines using carriage return (`\r`), relying on hardcoded padding spaces to overwrite old text is brittle and leads to trailing text artifacts when new lines are shorter than previous ones. **Action:** Always use the ANSI escape sequence `\033[K` (Erase in Line) immediately after the carriage return (`\r`) to cleanly clear the line before writing new content, rather than manually managing padding spaces. + +## 2024-05-24 - Readable Numerics and Achievement Context +**Learning:** In clicker-style games where scores can grow rapidly, raw integers become difficult to parse at a glance. Comma formatting (e.g., 1,234,567) significantly improves HUD readability. Additionally, "New Best" notifications are more impactful when they provide context by showing the previous record being surpassed. +**Action:** Always format large numeric values with thousands separators in terminal HUDs and include the previous high score in achievement celebrations to provide immediate context for the player's progress. diff --git a/src/main.cpp b/src/main.cpp index 60ae556..edce5b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include "utils.hpp" // Color and formatting macros for terminal output #define RESET "\033[0m" @@ -78,7 +79,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 " @@ -142,10 +143,10 @@ int main() { } if (updateUI) { - std::cout << "\r" ERASE_LINE << CLR_SCORE << "Score: " << score << CLR_RESET << " | High: " << highscore << " " + std::cout << "\r" ERASE_LINE << 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; + << (score > initialHighscore ? CLR_CTRL " ✨ NEW BEST! 🥳 (was " + formatWithCommas(initialHighscore) + ")" : "") + << CLR_RESET << std::flush; updateUI = false; } } @@ -155,9 +156,9 @@ 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"; + std::cout << CLR_CTRL << "✨ Congratulations! A new personal best! ✨" << CLR_RESET << "\n"; } std::cout << "Thanks for playing!\n"; std::cout << "\033[?25h" << std::flush; diff --git a/src/utils.hpp b/src/utils.hpp new file mode 100644 index 0000000..559f63a --- /dev/null +++ b/src/utils.hpp @@ -0,0 +1,20 @@ +#ifndef UTILS_HPP +#define UTILS_HPP + +#include + +/** + * Formats a long long value with thousands separators (commas). + * Example: 1234567 -> "1,234,567" + */ +inline std::string formatWithCommas(long long value) { + std::string s = std::to_string(value); + int insertPosition = static_cast(s.length()) - 3; + while (insertPosition > (value < 0 ? 1 : 0)) { + s.insert(insertPosition, ","); + insertPosition -= 3; + } + return s; +} + +#endif