From 8829fdb7ad6af3a86ab2c116cf58249f1af3c305 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 6 Jul 2026 17:30:18 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Implement=20comma=20f?= =?UTF-8?q?ormatting=20for=20scores=20and=20enhance=20"NEW=20BEST!"=20feed?= =?UTF-8?q?back?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added `src/utils.hpp` with a `formatWithCommas` helper function to improve score readability. - Updated `src/main.cpp` to use `formatWithCommas` for Personal Best, current Score, High Score, and Final Score displays. - Enhanced the "NEW BEST! 🥳" message with `CLR_CTRL` (Bold Yellow) and added context by showing the previous high score (e.g., "was 1,000"). - Verified changes with unit tests and existing UX validation scripts. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- src/main.cpp | 9 +++++---- src/utils.hpp | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/utils.hpp diff --git a/src/main.cpp b/src/main.cpp index 60ae556..7d92db4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include "utils.hpp" #include #include @@ -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,9 +143,9 @@ 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! 🥳" : "") + << (score > initialHighscore ? CLR_CTRL " NEW BEST! 🥳" CLR_RESET " (was " + formatWithCommas(initialHighscore) + ")" : "") << std::flush; updateUI = false; } @@ -155,7 +156,7 @@ 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"; } diff --git a/src/utils.hpp b/src/utils.hpp new file mode 100644 index 0000000..559eaba --- /dev/null +++ b/src/utils.hpp @@ -0,0 +1,17 @@ +#ifndef UTILS_HPP +#define UTILS_HPP + +#include + +inline std::string formatWithCommas(long long value) { + std::string s = std::to_string(value); + int insertPosition = static_cast(s.length()) - 3; + int limit = (value < 0) ? 1 : 0; + while (insertPosition > limit) { + s.insert(insertPosition, ","); + insertPosition -= 3; + } + return s; +} + +#endif