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
12 changes: 5 additions & 7 deletions .github/workflows/rust.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
name: Rust
name: C++ CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build
run: cargo build --verbose
run: make

- name: Run tests
run: cargo test --verbose
run: make test
10 changes: 0 additions & 10 deletions Cargo.toml

This file was deleted.

6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ $(TARGET): $(SRCS)
run: $(TARGET)
./$(TARGET)

# Test the game
test: $(TARGET)
echo 'q' | ./$(TARGET) | grep "Thanks for playing!"

# Clean up build artifacts
clean:
rm -f $(TARGET)

# Phony targets
.PHONY: all run clean
.PHONY: all run test clean
53 changes: 39 additions & 14 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
#include <poll.h>
#include <unistd.h>
#include <termios.h>
#include <algorithm>

#define RESET "\033[0m"
#define BOLD_GREEN "\033[1;32m"
#define BOLD_RED "\033[1;31m"
#define BOLD_BLUE "\033[1;34m"
#define BOLD_YELLOW "\033[1;33m"

int main() {
struct termios oldt, newt;
Expand All @@ -13,29 +20,47 @@ int main() {
tcsetattr(STDIN_FILENO, TCSANOW, &newt);

int score = 0; bool hardMode = false; char input;
std::cout << "==========================\n SPEED CLICKER\n==========================\n"
<< "Controls:\n [h] Toggle Hard Mode (10x Speed!)\n [q] Quit Game\n [Any key] Click!\n\n";
std::cout << BOLD_YELLOW << "==========================\n SPEED CLICKER\n==========================\n" << RESET
<< "Controls:\n"
<< BOLD_YELLOW << " [h] " << RESET << "Toggle Hard Mode (10x Speed!)\n"
<< BOLD_YELLOW << " [q] " << RESET << "Quit Game\n"
<< BOLD_YELLOW << " [Any key] " << RESET << "Click!\n\n";

struct pollfd fds[1] = {{STDIN_FILENO, POLLIN, 0}};
auto last_tick = std::chrono::steady_clock::now();
bool updateUI = true;
while (true) {
int timeout = hardMode ? 100 : 1000;
if (poll(fds, 1, 0) > 0) {
if (read(STDIN_FILENO, &input, 1) <= 0 || input == 'q') break;
if (input == 'h') {
hardMode = !hardMode;
std::cout << (hardMode ? "\n[HARD MODE] Speed x10!\n" : "\n[NORMAL MODE]\n");
} else score++;
if (updateUI) {
std::cout << "\r" << BOLD_GREEN << "Score: " << score << RESET << " "
<< (hardMode ? BOLD_RED "[HARD MODE] " : BOLD_BLUE "[NORMAL] ") << RESET
<< " (Press 'q' to quit) " << std::flush;
updateUI = false;
}

auto now = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_tick).count();
if (elapsed >= timeout) {
score++; last_tick = now;
std::cout << "Score: " << score << (hardMode ? " [FAST] " : " [NORMAL] ") << "\r" << std::flush;
int timeout = hardMode ? 100 : 1000;
int remaining = std::max(0, timeout - static_cast<int>(elapsed));

if (poll(fds, 1, remaining) > 0) {
if (read(STDIN_FILENO, &input, 1) <= 0 || input == 'q') break;
if (input == 'h') hardMode = !hardMode;
else score++;
updateUI = true;
}

now = std::chrono::steady_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_tick).count();
if (elapsed >= (hardMode ? 100 : 1000)) {
score++;
last_tick = now;
updateUI = true;
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
std::cout << "\nFinal Score: " << score << "\nThanks for playing!\n";
std::cout << "\n\n" << BOLD_YELLOW << "==========================\n" << RESET
<< BOLD_GREEN << " FINAL SCORE: " << score << RESET << "\n"
<< BOLD_YELLOW << "==========================\n" << RESET
<< " Thanks for playing!\n\n";
return 0;
}