Crates.io | gameboard |
lib.rs | gameboard |
version | 0.1.0 |
source | src |
created_at | 2019-03-03 17:26:44.069755 |
updated_at | 2019-03-03 17:26:44.069755 |
description | Rust library for creating game board for text UI games. |
homepage | |
repository | https://github.com/TimurShaykhiev/gameboard |
max_upload_size | |
id | 118447 |
size | 84,963 |
Rust library for creating game board for text UI games. Gameboard draws board in the terminal screen, updates cells, handles user IO and allows you to concentrate on the game logic. It can be used for classic table games with board with cell: tic-tac-toe, scrabble, sudoku, or for any text UI game where you can implement game field as a cell board.
Gameboard uses termion crate for terminal input/output.
Add to your Cargo.toml
:
[dependencies]
gameboard = "0.1.0"
Game creation:
use std::io::{self, Read, Write};
use std::cell::RefCell;
use std::rc::Rc;
use termion::event::Key;
use gameboard::{Board, Game, InputListener};
struct App {}
impl<R: Read, W: Write> InputListener<R, W> for App {
fn handle_key(&mut self, key: Key, game: &mut Game<R, W, Self>) {
match key {
Key::Char('q') => game.stop(),
_ => {}
}
}
}
fn main() {
let stdout = io::stdout();
let stdout = stdout.lock();
let stdin = io::stdin();
let stdin = stdin.lock();
let app = Rc::new(RefCell::new(App {}));
let board = Board::new(5, 5, 10, 5, true, None);
let game = Rc::new(RefCell::new(Game::new(stdin, stdout, Rc::clone(&app))));
game.borrow_mut().init(board, None);
game.borrow_mut().start();
}
Here you can see more examples of usage.
This project is licensed under the terms of the MIT license.