feat(frontend): improves current_status
This commit is contained in:
parent
e41eeaa890
commit
3c1d4f91b6
@ -83,31 +83,29 @@ impl Game {
|
|||||||
pub fn current_status(&self) -> Status {
|
pub fn current_status(&self) -> Status {
|
||||||
self.word.as_ref().map_or(Status::New, |_| {
|
self.word.as_ref().map_or(Status::New, |_| {
|
||||||
let word_count = self.submitted_words.len();
|
let word_count = self.submitted_words.len();
|
||||||
if self.tries == 0 {
|
match self.tries {
|
||||||
Status::New
|
0 => Status::New,
|
||||||
} else if self.tries < MAX_TRIES {
|
1..MAX_TRIES => self
|
||||||
if self
|
|
||||||
.submitted_words
|
.submitted_words
|
||||||
.last()
|
.last()
|
||||||
.unwrap()
|
.map_or(Status::InProgress, |words| {
|
||||||
.iter()
|
if words.iter().all(|v| matches!(v, CharStatus::Match(_))) {
|
||||||
.all(|v| matches!(v, CharStatus::Match(_)))
|
|
||||||
{
|
|
||||||
Status::Win(word_count)
|
Status::Win(word_count)
|
||||||
} else {
|
} else {
|
||||||
Status::InProgress
|
Status::InProgress
|
||||||
}
|
}
|
||||||
} else if self
|
}),
|
||||||
|
_ => self
|
||||||
.submitted_words
|
.submitted_words
|
||||||
.last()
|
.last()
|
||||||
.unwrap()
|
.map_or(Status::Lose(word_count), |words| {
|
||||||
.iter()
|
if words.iter().all(|v| matches!(v, CharStatus::Match(_))) {
|
||||||
.all(|v| matches!(v, CharStatus::Match(_)))
|
|
||||||
{
|
|
||||||
Status::Win(word_count)
|
Status::Win(word_count)
|
||||||
} else {
|
} else {
|
||||||
Status::Lose(word_count)
|
Status::Lose(word_count)
|
||||||
}
|
}
|
||||||
|
}),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user