diff --git a/96_Word/rust/src/progress.rs b/96_Word/rust/src/progress.rs index 22a14982..46bf4d39 100644 --- a/96_Word/rust/src/progress.rs +++ b/96_Word/rust/src/progress.rs @@ -16,4 +16,14 @@ impl Progress { print!("{}", c); } } + + pub fn done(&self) -> bool { + for c in self.chars { + if c == '-' { + return false; + } + } + + true + } } diff --git a/96_Word/rust/src/word_game.rs b/96_Word/rust/src/word_game.rs index 2402af9d..6df72acb 100644 --- a/96_Word/rust/src/word_game.rs +++ b/96_Word/rust/src/word_game.rs @@ -68,7 +68,7 @@ impl WordGame<'_> { } if guess.len() != 5 { - return invalid_input("You must guess a 5 letter word"); + return invalid_input("You must guess a 5 letter word."); } self.guess = guess.to_string(); @@ -91,18 +91,16 @@ impl WordGame<'_> { } } - let match_amount = matches.len(); - println!( "There were {} matches and the common letters were....{}", - match_amount, + matches.len(), matches.into_iter().collect::() ); print!("From the exact letter matches you know...."); self.progress.print(); - if match_amount == 5 { + if self.progress.done() { println!( "\n\nYou have guessed the word. It took {} guesses!\n", self.guesses