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-10 - Tactile Feedback in CLI
**Learning:** For terminal-based interactions, immediate UI updates upon keypress are crucial for "tactile" feel. Decoupling display updates from fixed game ticks and using `poll()` with dynamic timeouts provides a much smoother experience than busy-waiting or fixed sleep intervals.
**Action:** Always trigger a UI refresh immediately after processing user input in CLI games.
10 changes: 3 additions & 7 deletions .github/workflows/rust.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
name: Rust
name: C++ Build

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
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ run: $(TARGET)
clean:
rm -f $(TARGET)

# Test the game
test: $(TARGET)
echo "q" | ./$(TARGET) | grep "Final Score"

# Phony targets
.PHONY: all run clean
.PHONY: all run clean test
24 changes: 12 additions & 12 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <iostream>
#include <algorithm>
#include <chrono>
#include <thread>
#include <poll.h>
Expand All @@ -19,21 +20,20 @@ int main() {
struct pollfd fds[1] = {{STDIN_FILENO, POLLIN, 0}};
auto last_tick = std::chrono::steady_clock::now();
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++;
}
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 period = hardMode ? 100 : 1000;
int timeout = std::max(0, period - static_cast<int>(elapsed));

if (poll(fds, 1, timeout) > 0) {
if (read(STDIN_FILENO, &input, 1) <= 0 || input == 'q') break;
if (input == 'h') hardMode = !hardMode;
else score++;
} else {
score++;
last_tick = std::chrono::steady_clock::now();
}
std::this_thread::sleep_for(std::chrono::milliseconds(10));
std::cout << "Score: " << score << (hardMode ? " [FAST] " : " [NORMAL] ") << "\r" << std::flush;
}
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
std::cout << "\nFinal Score: " << score << "\nThanks for playing!\n";
Expand Down