Added playable round to letters game.

This commit is contained in:
2022-10-21 05:07:32 +02:00
parent 4534a1debe
commit 55343d5de7
7 changed files with 160 additions and 48 deletions

View File

@@ -3,6 +3,7 @@
const config = require('config');
const style = require('../utils/style');
const getWordKey = require('../utils/get-word-key');
const words = require('../../assets/mash-words.json');
const mashes = new Map();
@@ -10,10 +11,6 @@ const mashes = new Map();
const defineCommands = ['define', 'dict', 'dictionary'];
const resolveCommands = ['solve', 'resolve', 'lookup'];
function getWordKey(word) {
return word.split('').sort().join('');
}
function start(length, context, attempt = 0) {
const mash = mashes.get(context.room.id);
const lengthWords = words[length];
@@ -51,13 +48,13 @@ function start(length, context, attempt = 0) {
const newMash = mashes.get(context.room.id);
context.sendMessage(`Stomp stomp, here's your mash: ${style.bold(style.purple(newMash.anagram))}`, context.room.id);
context.sendMessage(`Stomp stomp, here's your mash: ${style.bold(style.pink(newMash.anagram))}`, context.room.id);
context.logger.info(`Mash started, '${anagram}' with answers ${answers.map((answer) => `'${answer.word}'`).join(', ')}`);
}
function play(rawWord, context, shouted) {
const mash = mashes.get(context.room.id);
const word = rawWord.toLowerCase();
const word = rawWord.trim().toLowerCase();
const key = getWordKey(word);
const answer = mash.answers.find((answerX) => answerX.word === word);
@@ -159,7 +156,7 @@ function hint(context) {
}
if (mash.anagram.length === 4) {
context.sendMessage(`Hints for ${style.bold(style.purple(mash.anagram))}, ${config.usernamePrefix}${context.user.username}: ${mash.answers.map((answer) => `${style.bold(`${answer.word.slice(0, 1)} ${'_ '.repeat(answer.word.length - 1).trim()}`)} (${answer.definitions[0]})`).join(', ')}`, context.room.id);
context.sendMessage(`Hints for ${style.bold(style.pink(mash.anagram))}, ${config.usernamePrefix}${context.user.username}: ${mash.answers.map((answer) => `${style.bold(`${answer.word.slice(0, 1)} ${'_ '.repeat(answer.word.length - 1).trim()}`)} (${answer.definitions[0]})`).join(', ')}`, context.room.id);
return;
}
@@ -192,7 +189,7 @@ function onCommand(args, context) {
}
if (!word && mash) {
context.sendMessage(`The current mash is: ${style.bold(style.purple(mash.anagram))}`, context.room.id);
context.sendMessage(`The current mash is: ${style.bold(style.pink(mash.anagram))}`, context.room.id);
return;
}