Trait HangmanBackend

Source
pub trait HangmanBackend {
    // Required methods
    fn new(config: &str) -> Result<Self, ConfigParseError>
       where Self: Sized;
    fn process_user_input(&mut self, inp: &str);
    fn render_image(&self) -> String;
    fn get_image_dimension(&self) -> (u8, u8);
    fn render_secret(&self) -> String;
    fn render_game_lifes(&self) -> String;
    fn render_game_last_guess(&self) -> String;
    fn render_instructions(&self) -> String;
    fn get_state(&self) -> State;
}
Expand description

API to interact with all game logic. This is used by the desktop frontend in main.rs or by the web-app frontend in lib.rs.

Required Methods§

Source

fn new(config: &str) -> Result<Self, ConfigParseError>
where Self: Sized,

Initialize the application with config data and start the first game.

Source

fn process_user_input(&mut self, inp: &str)

The user_input is a key stroke. The meaning depends on the game’s state:

Source

fn render_image(&self) -> String

Renders the image. Make sure it is up to date with self.image.update().

Source

fn get_image_dimension(&self) -> (u8, u8)

Forward the private image dimension

Source

fn render_secret(&self) -> String

Renders the partly hidden secret.

Source

fn render_game_lifes(&self) -> String

Informs about some game statistics: lifes

Source

fn render_game_last_guess(&self) -> String

Informs about some game statistics: last guess

Source

fn render_instructions(&self) -> String

Tells the user what to do next.

Source

fn get_state(&self) -> State

Forwards the game’s state

Implementors§