From 856da24488168a5923e2948d30361334ce9a7eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?U=C4=9Fur=20K=C3=BCpeli?= Date: Tue, 3 May 2022 10:28:20 +0300 Subject: [PATCH] fixed win state condition --- 96_Word/rust/src/progress.rs | 10 ++++++++++ 96_Word/rust/src/word_game.rs | 8 +++----- 2 files changed, 13 insertions(+), 5 deletions(-) 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