From d7186632d577f52543ddf80eaeffdcea8d791811 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Sat, 18 Feb 2023 21:17:37 +0100 Subject: [PATCH] feedback after failed guess attempt --- src/components/GuessingGame.vue | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/GuessingGame.vue b/src/components/GuessingGame.vue index 2e99e26..8b8458e 100644 --- a/src/components/GuessingGame.vue +++ b/src/components/GuessingGame.vue @@ -23,6 +23,7 @@ +

{{error}}

{{ title }}

@@ -54,6 +55,7 @@ export default { answerRevealed: false, titles: [], guessPhrase: "", + error: "", displayData: { synopsis: "" }, @@ -109,6 +111,7 @@ export default { // synopsis less than 30 words if (animeDatajson.synopsis.split(" ").length < 50) return false; + // not a hentai for (const genreId in animeDatajson.genres) { const genre = animeDatajson.genres[genreId].name; if (genre == null) continue; @@ -128,15 +131,28 @@ export default { guess() { for (const titleId in this.titles) { const title = this.titles[titleId]; - if (levenshtein(title.toLowerCase(), this.guessPhrase.toLowerCase()) <= 1) { + const distance = levenshtein(title.toLowerCase(), this.guessPhrase.toLowerCase()); + if (distance <= 1) { this.answerRevealed = true; this.setDisplayData(false) + this.error = ""; return; } + if (distance < 3) { + this.error = "Almost correct!"; + return; + } + if (distance < 5) { + this.error = "You're getting close!" + return; + } + + this.error = "Incorrect!"; } }, giveUp() { this.answerRevealed = true; + this.error = ""; this.setDisplayData(false) } },