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