From 1764eb9c530b68d10102a249a2c13910972b1d1d Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Thu, 19 Jan 2023 12:46:20 -0600 Subject: [PATCH] Make the max limit count actually end the game --- src/endpoints/guess_letter.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/endpoints/guess_letter.ts b/src/endpoints/guess_letter.ts index f23c995..205c711 100644 --- a/src/endpoints/guess_letter.ts +++ b/src/endpoints/guess_letter.ts @@ -1,4 +1,4 @@ -import { database } from "$/main"; +import { config, database } from "$/main"; import { addLetter } from "$/utils/game"; import { ServerRoute } from "@hapi/hapi"; import Joi from "joi"; @@ -22,12 +22,15 @@ const route: ServerRoute = { let data = await database.getChannel(channel); console.log(data) - if (data.solution.includes(guess)) { + if (data.key[guess] != null) { data.current = addLetter(data.key, data.current, guess); } else { data.incorrect++; }; - return `${data.current} (incorrect: ${data.incorrect}/6)`; + if (data.incorrect >= config.game.max_incorrect) { + return `Oop, you ded. Answer: ${data.solution}`; + }; + return `${data.current} (incorrect: ${data.incorrect}/${config.game.max_incorrect})`; }, }; export default route; \ No newline at end of file