| Crates.io | tgames |
| lib.rs | tgames |
| version | 0.3.3 |
| created_at | 2024-04-28 17:35:37.240071+00 |
| updated_at | 2026-01-22 12:01:40.386788+00 |
| description | A collection of little terminal games |
| homepage | |
| repository | https://github.com/enfmarinho/tgames.git |
| max_upload_size | |
| id | 1223397 |
| size | 5,100,649 |
A terminal-based mini-games emulator.
tgames is built with scalability in mind. It uses a Trait-based abstraction to handle game logic, allowing for easy expansion.
Games enum and implementing the GameManager trait for a new struct. No changes to the core engine are requiredThe engine uses the Strategy Pattern to remain decoupled from game logic. To add a new game, simply implement the GameManager trait and register it in the central dispatcher.
impl GameManager for MyNewGame {
fn process_events(&mut self) -> Result<()> { /* Handle non-blocking input */ }
fn update(&mut self) -> Result<()> { /* Physics & Logic */ }
fn render(&mut self, terminal: &mut ...) { /* Draw to TUI via Ratatui */ }
fn reset(&mut self) { /* Re-initialize state */ }
fn ended(&self) -> bool { /* Game Over condition */ }
fn kill_execution(&self) -> bool { /* Kill game execution condition */ }
}
Add the variant to the Games enum. The engine handles the lifecycle and state transitions automatically. New games are registered within the run_game dispatcher:
fn run_game(&mut self) -> Result<()> {
// more code...
match game {
Games::MyNewGame => self.game_instance[index]
.get_or_insert_with(|| Box::new(MyNewGame::new()))
.run(&mut self.terminal),
// Other games logic...
_ => { /* ... */ }
}
// more code...
}
The installation can be done via cargo, just use:
cargo install tgames
I chose Rust for this project not just for its modern syntax, but for the specific guarantees it provides for systems-level development:
Fearless Concurrency: Rustโs ownership model ensured that my multi-threaded input handling remained data-race free, allowing for a stable, non-blocking game loop.
Deterministic Resource Management: Rust allows for precise control over heap allocations. This ensures that the runtime execution and memory footprint of the program to remain highly predictable.
Zero-Cost Abstractions: The Trait-based architecture used in tgames allows for high-level modularity without sacrificing the performance of the underlying machine code.
Learning: Beyond the technical requirements, I chose Rust out of curiosity and desire to master a modern approach to systems design. I wanted to move away from manual memory management and learn the Borrow Checker to improve my ability to write memory-safe software.