Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake CLI

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.

Features

  • Terminal UI using crossterm with 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.

Requirements

Build

From the repository root, run:

cargo build --release

This produces the executable in target/release/snake_cli.exe (on Windows) or target/release/snake_cli on Unix.

Run

Run the compiled binary or use cargo run for development:

cargo run --release

When 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.

Configuration

You can tweak constants in src/main.rs to change gameplay:

  • WIDTH and HEIGHT — playable area size (inner dimensions)
  • TICK_MS — game tick in milliseconds (lower = faster)

After changing, rebuild with cargo build or run with cargo run.

Development notes

  • 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 rand crate; ensure dependencies are present by running cargo build.

License

Licensed under the MIT License. See LICENSE file for details.

Troubleshooting

  • 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.

Next steps / Ideas

  • Add high score persistence.
  • Add sound effects (platform dependent).
  • Add colors/themes and a difficulty slider.

About

Terminal-based Snake game written in Rust

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages