Skip to main content

Module arcade

Module arcade 

Source
Expand description

SyntaxBreaker — a zero-dependency terminal typing game.

You get 60 seconds to type code snippets as fast as you can. Type each snippet exactly (case-sensitive); it auto-submits once you have typed the full length. Speed earns the bonus, mistakes cost points, and a timeout on any single snippet forces a retry-or-skip decision.

The module is self-contained: terminal access goes through a small GameKeyReader / GameWriter abstraction (backed by crossterm, which is already a crate dependency) so the whole game loop is unit-testable with [MockGameKeyReader], [CapturingGameWriter] and a stepped GameClock.

High scores live in .limitless/arcade_scores.json (top 5, descending).

use limitless_cli::modules::arcade::score_attempt;

// Correct scrape, fast = 10 points + 5 bonus.
assert_eq!(score_attempt(true, true), 15);
// Correct but slow = base points only.
assert_eq!(score_attempt(true, false), 10);
// Missed attempt = flat penalty.
assert_eq!(score_attempt(false, false), -2);

Structs§

ArcadeResult
Summary of one finished game, before it is written to the leaderboard.
ArcadeScoreboard
Serialized top-5 leaderboard stored in arcade_scores.json.
StdoutGameWriter
Writer backed by the real standard output.
StepClock
Deterministic test clock: each now() call advances by POLL_TIMEOUT, modelling one poll interval passing on a real machine.
SystemGameClock
Clock backed by the real system time.
TerminalGameKeyReader
Key reader backed by a real terminal via the crossterm crate.

Enums§

GameKey
A normalized key press the game understands.
StatusLine
One line of the status area inside the game box.

Constants§

ARCADE_WIDTH
Fixed-width box used for every game frame.
ATTEMPT_LIMIT
A single snippet must be completed within this window.
BONUS_POINTS
Extra points when a snippet is completed in under BONUS_WINDOW.
BONUS_WINDOW
Completing faster than this earns the speed bonus.
CORRECT_POINTS
Points for a correctly typed snippet.
GAME_DURATION
How long one full game lasts.
MAX_SCORES
Max scores kept on the leaderboard.
PENALTY
Points lost per wrong character (and for a timed-out attempt).
POLL_TIMEOUT
How long the key reader waits for a key before the loop re-checks clocks.
SCORE_DIR
Directory (under the current working directory) holding game data.
SCORE_FILE
Score file name inside SCORE_DIR.
SNIPPETS
The snippet database the game draws from.

Traits§

GameClock
Output stream for the game; now returns the current instant.
GameKeyReader
Abstraction over the terminal so the game can be driven by mock input.
GameWriter
Abstraction over the output stream so the game can capture its frames.

Functions§

is_new_high_score
Whether score beats the previous best, i.e. every score strictly above previous_top deserves the 🏆 banner (the very first game counts).
render_frame_plain
Renders one full frame of the game (ANSI-free).
render_scoreboard
The little leaderboard shown before a game starts.
run_arcade
CLI entry point behind limit arcade.
run_typing_game
Plays a full 60-second game on the real terminal, then persists and ranks the score, printing the final tally and leaderboard.
score_attempt
Scores one completed attempt.
score_file_path
Where the leaderboard lives: .limitless/arcade_scores.json in the CWD.
shuffled_with
Shuffles the snippet pool with seed so every game draws a fresh order.