From 256bce6abcc9514c5d94b3ca6e4c0068b83e9792 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Fri, 24 Feb 2023 08:29:37 -0700 Subject: [PATCH] Change the return structure and store what the users have guessed already --- src/endpoints/guess.ts | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/endpoints/guess.ts b/src/endpoints/guess.ts index 30d9c6c..b65739c 100644 --- a/src/endpoints/guess.ts +++ b/src/endpoints/guess.ts @@ -33,6 +33,18 @@ const route: ServerRoute = { // The user is guessing a single letter if (type === `letter`) { + + if (data.guesses.includes(guess)) { + data.incorrect += config.game.penalties.duplicate; + return { + status: 1, + current: data.current, + incorrect: data.incorrect, + won, + }; + } + data.guesses.push(guess); + if (data.key[guess] != null) { data.current = addLetter(data.key, data.current, guess); won = data.current == data.solution; @@ -66,7 +78,11 @@ const route: ServerRoute = { // NOTE: This might cause reference issues with the return await database.resetChannel(channel); - return `Congrats! You won. Merry Chatmanmas! Answer: ${data.solution}`; + return { + status: 2, + current: data.current, + incorrect: data.incorrect, + }; }; @@ -82,7 +98,11 @@ const route: ServerRoute = { // NOTE: This might cause reference issues with the return await database.resetChannel(channel); - return `Oop, you ded. Answer: ${data.solution}`; + return { + status: 3, + current: data.current, + incorrect: data.incorrect, + }; }; @@ -100,7 +120,11 @@ const route: ServerRoute = { max: config.game.max_incorrect, }, }); - return `${data.current} (incorrect: ${data.incorrect}/${config.game.max_incorrect})`; + return { + status: 4, + current: data.current, + incorrect: data.incorrect, + }; }, }; export default route; \ No newline at end of file