Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-06-25 - Data Readability and Achievement Context
**Learning:** In numeric-heavy CLI applications, formatting large numbers with thousands separators (e.g., `1,000,000`) significantly reduces cognitive load. Furthermore, when a user achieves a new personal best, providing the previous record for context transforms a generic "Success" message into a meaningful achievement celebration.
**Action:** Implement a `formatWithCommas` utility for all numeric displays in CLI apps and always provide "previous state" context when announcing new records or milestones.
27 changes: 21 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,23 @@
#define CLR_HARD "\033[1;31m"
#define CLR_NORM "\033[1;32m"
#define CLR_CTRL "\033[1;33m"
#define CLR_EOL "\033[K"
#define CLR_RESET "\033[0m"

struct termios oldt;

std::string formatWithCommas(long long value) {
std::string s = std::to_string(value);
int n = static_cast<int>(s.length());
int limit = (value < 0) ? 1 : 0;
int insertPosition = n - 3;
while (insertPosition > limit) {
s.insert(insertPosition, ",");
insertPosition -= 3;
}
return s;
}

void restore_terminal(int signum) {
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
// Use write() and _exit() because they are async-signal-safe
Expand Down Expand Up @@ -77,7 +90,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 << " " << CLR_SCORE << "Personal Best: " << formatWithCommas(highscore) << CLR_RESET << "\n\n";
}

std::cout << "Controls:\n " << CLR_CTRL << "[h]" << CLR_RESET << " Toggle Hard Mode (10x Speed!)\n "
Expand Down Expand Up @@ -141,10 +154,11 @@ 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
<< " | " << CLR_SCORE << "High: " << formatWithCommas(highscore) << CLR_RESET << " "
<< (hardMode ? CLR_HARD "[HARD MODE]" : CLR_NORM "[NORMAL MODE]")
<< (score > initialHighscore ? " NEW BEST! 🥳" : "")
<< " " << std::flush;
<< (score > initialHighscore ? CLR_NORM " NEW BEST! 🥳" CLR_RESET : "")
<< CLR_EOL << std::flush;
updateUI = false;
}
}
Expand All @@ -154,9 +168,10 @@ 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_NORM << "Congratulations! A new personal best! " << CLR_RESET
<< "(Previous: " << formatWithCommas(initialHighscore) << ")\n";
}
std::cout << "Thanks for playing!\n";
std::cout << "\033[?25h" << std::flush;
Expand Down
Loading