fixed win state condition

This commit is contained in:
Uğur Küpeli
2022-05-03 10:28:20 +03:00
parent 056312f359
commit 856da24488
2 changed files with 13 additions and 5 deletions

View File

@@ -16,4 +16,14 @@ impl Progress {
print!("{}", c);
}
}
pub fn done(&self) -> bool {
for c in self.chars {
if c == '-' {
return false;
}
}
true
}
}

View File

@@ -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::<String>()
);
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