diff --git a/README.md b/README.md index a260de7..8fc07b0 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,8 @@ Guess commands are character sequences you can guess to do additional behavior. |command|description| |---|---| |!ans[wer]|shows the answer to the current wordle| + + +## Screenshots + +![gif of wordle in terminal](images/wordle_rust.gif) diff --git a/src/main.rs b/src/main.rs index 7ba79aa..85f4198 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ mod wordle; use utils::str_unique_by_characters; use wordle::{worlde_game_make_guess, WordleState}; +use crate::utils::clear_screen; fn generate_wordle_dictionary() -> HashSet { let existing_path = "./dictionaries/output/five_letter_words.txt"; @@ -90,10 +91,12 @@ fn main() { .filter(|x| str_unique_by_characters(x)) .map(|w| w) .collect(); - let worlde_answer = unique_words.choose(&mut rand::thread_rng()).unwrap(); + let worlde_answer = String::from("EXAMS"); //unique_words.choose(&mut rand::thread_rng()).unwrap(); let mut wordle_game_state = WordleState::new(worlde_answer.as_str()); + + clear_screen(); loop { let mut input; @@ -112,6 +115,7 @@ fn main() { } worlde_game_make_guess(input.as_ref(), &mut wordle_game_state); + clear_screen(); print!("Board:\n{}", wordle_game_state); if wordle_game_state.game_over() { break; diff --git a/src/utils.rs b/src/utils.rs index c51bbdf..e21d934 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -20,3 +20,7 @@ pub fn str_to_five_char(s: &str) -> [char; 5] { arr }) } + +pub fn clear_screen() { + print!("\x1B[2J\x1B[1;1H"); +} diff --git a/src/wordle.rs b/src/wordle.rs index 50b85c3..7ec1b35 100644 --- a/src/wordle.rs +++ b/src/wordle.rs @@ -153,11 +153,6 @@ impl fmt::Display for WordleState { pub fn worlde_game_make_guess(guess: &str, state: &mut WordleState) { let turn = state.guesses.iter().position(|guess| guess.is_none()); - match turn { - Some(t) => println!("Current turn index: {}", t), - None => println!("Game is over"), - } - if turn.is_some() { let turn = turn.unwrap(); state.set_guess(turn, str_to_five_char(guess));