init
This commit is contained in:
commit
b130df0391
16 changed files with 339925 additions and 0 deletions
43
src/game/proxy.rs
Normal file
43
src/game/proxy.rs
Normal file
|
@ -0,0 +1,43 @@
|
|||
use std::io::{self, Write};
|
||||
|
||||
use super::{Game, Info};
|
||||
|
||||
pub struct Proxy {
|
||||
length: usize,
|
||||
}
|
||||
|
||||
impl Proxy {
|
||||
pub fn init() -> (Self, Vec<Info>) {
|
||||
println!("Infos.");
|
||||
let infos = prompt();
|
||||
let infos = Info::from_init(infos.chars());
|
||||
let length = infos.len();
|
||||
(Self { length }, infos)
|
||||
}
|
||||
}
|
||||
|
||||
impl Game for Proxy {
|
||||
fn guess(&mut self, word: &str) -> Result<(), Vec<Info>> {
|
||||
println!("Guessing");
|
||||
println!(" {word}");
|
||||
loop {
|
||||
let result = prompt();
|
||||
let Some(infos) = Info::from_printable(result.chars(), word.chars()) else {
|
||||
continue;
|
||||
};
|
||||
return Err(infos);
|
||||
}
|
||||
}
|
||||
|
||||
fn length(&mut self) -> usize {
|
||||
self.length
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt() -> String {
|
||||
print!("> ");
|
||||
io::stdout().flush().ok();
|
||||
let mut line = String::new();
|
||||
io::stdin().read_line(&mut line).unwrap();
|
||||
line.trim_end_matches("\n").to_string()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue