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 @@ -6,3 +6,7 @@

## 2026-01-09 - Terminal I/O and Blocking
**Learning:** Standard terminal I/O is line-buffered by default. For real-time games, it's essential to use non-canonical mode (raw mode) to capture keypresses immediately. Also, internal journals should be kept clean if they are to be included in the repo.

## 2026-01-09 - Tactile CLI Feedback
**Learning:** For terminal-based games, users expect immediate visual confirmation of their actions. Triggering a UI redraw instantly on input events—rather than waiting for the next timer-based tick—makes the application feel significantly more responsive.
**Action:** Always call the display update function immediately after processing user input, and use carriage returns (`\r`) with padding to maintain a clean, single-line interface.
13 changes: 6 additions & 7 deletions .github/workflows/rust.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
name: Rust
name: Build and Test

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: |
echo "aaaq" | ./game | grep "Final Score: 3"
34 changes: 24 additions & 10 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <poll.h>
#include <unistd.h>
#include <termios.h>
#include <algorithm>

int main() {
struct termios oldt, newt;
Expand All @@ -18,22 +19,35 @@ int main() {

struct pollfd fds[1] = {{STDIN_FILENO, POLLIN, 0}};
auto last_tick = std::chrono::steady_clock::now();
auto updateDisplay = [&](int s, bool hm) {
std::cout << "\rScore: " << s << (hm ? " [HARD MODE] " : " [NORMAL] ") << std::flush;
};

updateDisplay(score, hardMode);

while (true) {
int timeout = hardMode ? 100 : 1000;
if (poll(fds, 1, 0) > 0) {
int interval = hardMode ? 100 : 1000;
auto now = std::chrono::steady_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_tick).count();
int timeout = std::max(0, static_cast<int>(interval - elapsed));

if (poll(fds, 1, timeout) > 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++;
} else {
score++;
}
updateDisplay(score, hardMode);
}
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;

now = std::chrono::steady_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(now - last_tick).count();
if (elapsed >= interval) {
score++;
last_tick = now;
updateDisplay(score, hardMode);
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
std::cout << "\nFinal Score: " << score << "\nThanks for playing!\n";
Expand Down