extern crate specs_engine; use specs_engine::{ EventContext, ApplicationConfig, Context, World, State, ApplicationBuilder }; use std::io; use std::process::exit; struct STD; impl EventContext for STD { type Event = String; fn next_event(&mut self) -> Option { let mut input = String::new(); match io::stdin().read_line(&mut input) { Ok(_) => { Some(input) } Err(error) => panic!("error: {}", error), } } fn send_event(&mut self, event: Self::Event) { println!("{}",event); } } struct STATE; impl State for STATE { type Event = String; fn startup(&mut self, _: &mut World, ctx: &mut Context) { ctx.send_event("\nTry and guess the number im thinking!".to_string()); } fn handle_event(&mut self, _world: &mut World, _ctx: &mut Context, mut _event: Self::Event) { _event.pop(); if let Ok(d) = _event.parse::() { if d == 25 { _ctx.send_event("\nYay you guessed right!\n".to_string()); exit(0); } else { _ctx.send_event("\nWrong try again!\n".to_string()); } } else { _ctx.send_event("Are you stupid I said number!".to_string()); } } fn name(&self) -> Option<&str> { Some("Guessing Game") } } fn main() { let mut c = ApplicationConfig::new(Box::new(STD)); c.add_initial_state(Box::new(STATE)); c.fps = 1000; let mut app = ApplicationBuilder::new(c) .done(); app.run(); }