From c9f04900769a8bff0d20142dd098c3c16234673d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 11 Mar 2026 17:15:17 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Enhance=20game=20feed?= =?UTF-8?q?back=20and=20visual=20polish?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implemented several micro-UX improvements to the CLI game: - Colorized countdown digits and "GO!" prompt for better visual feedback. - Used ANSI escape sequence \033[K for cleaner line clearing. - Added live high score to the gameplay UI. - Made "NEW BEST!" and final congratulations inclusive for first-time players. - Highlighted interaction keywords in the start prompt. - Updated Palette journal with learnings on terminal UI and inclusive logic. Co-authored-by: aidasofialily-cmd <247843425+aidasofialily-cmd@users.noreply.github.com> --- .Jules/palette.md | 8 ++++++++ src/main.cpp | 15 ++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.Jules/palette.md b/.Jules/palette.md index c4e3778..61960aa 100644 --- a/.Jules/palette.md +++ b/.Jules/palette.md @@ -25,3 +25,11 @@ ## 2026-03-02 - Hiding the Cursor in CLI Games **Learning:** In terminal applications that require rapid visual updates or where user input doesn't involve typing text, an actively blinking cursor can be a visual distraction. Hiding it during interaction (`\033[?25l`) and rigorously ensuring it is restored (`\033[?25h`) on exit—including signal interrupts—significantly improves the aesthetic and focus. **Action:** Always hide the cursor for interactive CLI games and explicitly restore it across all exit paths, including async-signal-safe signal handlers. + +## 2026-05-24 - Cleaner Terminal UI with Erase Line +**Learning:** Using manual trailing spaces to clear previous output on a carriage-returned line is brittle and error-prone. The ANSI escape sequence \033[K (Erase in Line) provides a robust way to clear the remainder of the line from the cursor position, ensuring a clean UI regardless of string length changes. +**Action:** Prefer \033[K over manual padding when performing in-place terminal updates. + +## 2026-05-24 - Inclusive Achievement Logic +**Learning:** Requiring a pre-existing non-zero high score before triggering "New Best" or congratulations messages excludes first-time players from initial delight. Celebrating the first-ever score as a personal best provides immediate positive reinforcement and a stronger initial hook. +**Action:** Ensure achievement and celebration logic is inclusive of first-time interactions by not requiring a non-zero baseline. diff --git a/src/main.cpp b/src/main.cpp index e72f1da..4eba4c9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -83,7 +83,7 @@ int main() { std::cout << "Controls:\n " << CLR_CTRL << "[h]" << CLR_RESET << " Toggle Hard Mode (10x Speed!)\n " << CLR_CTRL << "[q]" << CLR_RESET << " Quit Game\n " << CLR_CTRL << "[Any key]" << CLR_RESET << " Click!\n\n"; - std::cout << "Press any key to start... " << std::flush; + std::cout << "Press " << CLR_CTRL << "any key" << CLR_RESET << " to start... " << std::flush; struct pollfd start_fds[1] = {{STDIN_FILENO, POLLIN, 0}}; if (poll(start_fds, 1, -1) > 0) { if (read(STDIN_FILENO, &input, 1) > 0 && input == 'q') { @@ -94,7 +94,7 @@ int main() { } for (int i = 3; i > 0; --i) { - std::cout << "\rStarting in " << i << "... " << std::flush; + std::cout << "\r\033[KStarting in " << CLR_CTRL << i << CLR_RESET << "... " << std::flush; auto start_wait = std::chrono::steady_clock::now(); while (std::chrono::duration_cast(std::chrono::steady_clock::now() - start_wait).count() < 1000) { int elapsed = std::chrono::duration_cast(std::chrono::steady_clock::now() - start_wait).count(); @@ -108,7 +108,7 @@ int main() { } } } - std::cout << "\rGO! \n" << std::flush; + std::cout << "\r\033[K" << CLR_NORM << "GO!" << CLR_RESET << "\n" << std::flush; std::this_thread::sleep_for(std::chrono::milliseconds(200)); tcflush(STDIN_FILENO, TCIFLUSH); @@ -137,10 +137,11 @@ int main() { } if (updateUI) { - std::cout << "\r" << CLR_SCORE << "Score: " << score << CLR_RESET << " " + std::cout << "\r\033[K" << CLR_SCORE << "Score: " << score << CLR_RESET + << " | High: " << CLR_SCORE << (score > highscore ? score : highscore) << CLR_RESET << " " << (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]") - << (score > initialHighscore && initialHighscore > 0 ? " NEW BEST! 🥳" : "") - << " " << std::flush; + << (score > initialHighscore ? " NEW BEST! 🥳" : "") + << std::flush; updateUI = false; } } @@ -151,7 +152,7 @@ int main() { tcsetattr(STDIN_FILENO, TCSANOW, &oldt); std::cout << "\n\n" << CLR_SCORE << "Final Score: " << score << CLR_RESET << "\n"; - if (score > initialHighscore && initialHighscore > 0) { + if (score > initialHighscore) { std::cout << "Congratulations! A new personal best!\n"; } std::cout << "Thanks for playing!\n";