Skip to content

asaft29/r2048

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

r2048

Linux Build macOS Build Windows Build Crates.io

r2048 Demo

r2048 is a terminal version of the classic 2048 game, built in Rust using the ratatui crate for the UI design.

Preview


Menu screen
Menu

Mid-game action with colorful tiles
Mid-game

Victory screen celebration
ʕ·͡ᴥ·ʔ Winning ʕ·͡ᴥ·ʔ

Game over screen
ಡ_ಡ Losing ಡ_ಡ


Controls That Just Make Sense

Main Menu

  • / – Browse your options like a pro
  • E – Dive into the action
  • Q or Esc – Exit the game gracefully

In the Game

  • / / / – Slide those tiles with precision
  • Q or Esc – Takes you back to the menu when things get tough
  • Ctrl + C – Nuclear option (closes everything immediately)

Score Persistence

High scores now persist between sessions thanks to a built-in SQLite database.

Whether you quit the game, close your terminal, or reboot your machine, your top scores are safely stored — no setup required.

Each user has a separate score history, so you can challenge friends on the same machine without stepping on each other’s records. It’s simple, fast, and completely local.


Development Notes

  • C++ Background: Coming from C++, Rust’s borrow checker encouraged cleaner, safer code structure.

  • State Machine: Using enums and pattern matching, the game’s states (Menu, Playing, Won, GameOver) are clear and type-safe.

  • Game Logic: Implementing merge rules correctly without double merges was the trickiest part — it took several rewrites to get right.
    ker encouraged

  • Code Quality: Rust’s strictness helped catch subtle edge cases and improved overall code reliability.


Getting Started

1. Via crates.io:

If Rust is installed and you don't want to clone the repo, consider using cargo install

cargo install r2048

r2048

2. Build it yourself

First, make sure you have Rust installed on your system. If not, grab it from rust-lang.org – it's surprisingly painless.

# Clone the repo
git clone https://github.com/asaft29/r2048.git

cd r2048

# Run it immediately with no verbose output showing (Cargo will handle the build)
cargo run --release 

Warning

There are some potential issues with cargo install if you are on Windows

  • stdarg.h missing → install C++ build tools + Windows SDK
  • libsqlite3-sys fails → MSVC headers required