Terminal-based Snake game written in Rust using crossterm.
This small project is a classic snake game you can play entirely inside your terminal. It supports two difficulty modes (Normal = wrap-around walls, Hard = walls kill), keyboard controls (arrow keys or WASD), and shows your score.
- Terminal UI using
crosstermwith alternate screen and raw mode. - Random food spawning with collision avoidance.
- Two difficulty modes: Normal (wrap-around) and Hard (walls are fatal).
- Simple HUD with score and controls.
- Rust toolchain (stable) — https://www.rust-lang.org/tools/install
- Tested on Windows using the MSVC toolchain; it should work on Unix-like systems as well.
From the repository root, run:
cargo build --releaseThis produces the executable in target/release/snake_cli.exe (on Windows) or target/release/snake_cli on Unix.
Run the compiled binary or use cargo run for development:
cargo run --releaseWhen the game starts you will see a difficulty menu. Use Up/Down or W/S to select, Enter to start. During play:
- Arrow keys or WASD — move the snake
- Q or Esc — quit
- Ctrl+C — quit
On Game Over you can press R to restart or Q to quit.
You can tweak constants in src/main.rs to change gameplay:
WIDTHandHEIGHT— playable area size (inner dimensions)TICK_MS— game tick in milliseconds (lower = faster)
After changing, rebuild with cargo build or run with cargo run.
- The game uses an alternate terminal screen and enables raw mode. If the program exits unexpectedly the terminal may remain in a weird state; the code attempts to restore the terminal on normal exit. If your terminal looks broken, run
reset(on Unix) or close and reopen your terminal on Windows. - Random food uses the
randcrate; ensure dependencies are present by runningcargo build.
Licensed under the MIT License. See LICENSE file for details.
- If build fails on Windows, ensure you have the Visual Studio Build Tools / C++ toolchain installed for the MSVC target.
- If the terminal doesn't restore after a crash, try closing the terminal window or running a fresh shell.
- Add high score persistence.
- Add sound effects (platform dependent).
- Add colors/themes and a difficulty slider.