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
9 changes: 5 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <unistd.h>
#include <termios.h>
#include <algorithm>
#include "utils.hpp"
#include <csignal>
#include <cstdlib>

Expand Down Expand Up @@ -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 "
Expand Down Expand Up @@ -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;
}
Expand All @@ -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";
}
Expand Down
17 changes: 17 additions & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef UTILS_HPP
#define UTILS_HPP

#include <string>

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

#endif
Loading