console-games 0.1.6

A collection of console games written in Rust
Documentation

console games

A hobby project for console games. New games are coming, hopefully 🙂🙂🙂. And I'm open for contributions.

Usage

use console_games::game_center::GameCenter;

fn main() {
    GameCenter::enter();
}

Games

List of available games:

  • Guess the Word
  • Guess the Number
  • Word Type

To run an individual game

use console_games::{games::guess_the_word::GuessTheWord, Play};

fn main() {
    println!("{}", GuessTheWord.name());
    GuessTheWord.print_intro();
    GuessTheWord.start();
}

Contribution

I need your help!!! Let's grow this project together. If you have any ideas, wether it's a new game, performance improvements, etc, please open an issue or a pull request.

To create a game

A game must implement the Play trait.

// games/my_game.rs

pub struct MyGame;

impl Play for MyGame {
    fn name(&self) -> &'static str {
        "My Game"
    }

    fn start(&mut self) {
        println!("Starting my game");
    }
}

Lastly, make the game visible in the module tree.

// games.rs

// --- snip ---
pub mod my_game;

To add a new game to the game center

Add the game to the return value of GameCenter::games method.

// game_center.rs

// --- snip ---

impl GameCenter {
    // --- snip ---

    pub fn games() -> [Box<dyn Play>; 4 /* <-- change this number */] {
        [
            Box::new(guess_the_word::GuessTheWord),
            Box::new(guess_the_number::GuessTheNumber),
            Box::new(word_type::WordType),
            Box::new(my_game::MyGame), // <-- add this line
        ]
    }

    // --- snip ---
}