Added stub for letters game.
This commit is contained in:
parent
78b7d95d3f
commit
6701f5e5a1
|
@ -33,4 +33,7 @@ module.exports = {
|
|||
interval: [10, 3600], // seconds
|
||||
duck: ':duck:',
|
||||
},
|
||||
letters: {
|
||||
length: 9,
|
||||
},
|
||||
};
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
'use strict';
|
||||
|
||||
const config = require('config');
|
||||
|
||||
const shuffle = require('../utils/shuffle');
|
||||
const style = require('../utils/style');
|
||||
|
||||
const availableVowels = ['a', 'e', 'i', 'o', 'u'];
|
||||
const availableConsonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']; // Countdown regards y as a consonant
|
||||
|
||||
const games = new Map();
|
||||
|
||||
function getBoard(context) {
|
||||
const game = games.get(context.room.id);
|
||||
|
||||
return `${game.word.split('').map((letter) => `${style.grey('[')}${letter.toUpperCase()}${style.grey(']')}`).join('')}${`${style.silver('[')} ${style.silver(']')}`.repeat(config.letters.length - game.word.length)}`;
|
||||
}
|
||||
|
||||
function shuffleLetters(letters, acc = []) {
|
||||
const shuffled = shuffle(letters, config.letters.length);
|
||||
|
||||
if (acc.length + shuffled.length < config.letters.length) {
|
||||
return shuffleLetters(letters, [...acc, ...shuffled, ...letters]);
|
||||
}
|
||||
|
||||
return [...acc, ...shuffled].slice(0, config.letters.length);
|
||||
}
|
||||
|
||||
function playRound(context) {
|
||||
context.sendMessage(`${getBoard(context)} Let's start!`, context.room.id);
|
||||
}
|
||||
|
||||
function pickLetter(type, context) {
|
||||
const game = games.get(context.room.id);
|
||||
|
||||
if (!game || game.word.length === config.letters.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
game.word = `${game.word}${game[type].pop()}`;
|
||||
|
||||
if (game.word.length === config.letters.length) {
|
||||
playRound(context);
|
||||
return;
|
||||
}
|
||||
|
||||
context.sendMessage(`${getBoard(context)} Would you like a consonant or a vowel?`, context.room.id);
|
||||
}
|
||||
|
||||
function start(context) {
|
||||
if (games.has(context.room.id)) {
|
||||
context.sendMessage(`${getBoard(context)} This is the current board. Use ${config.prefix}letters:stop to reset.`, context.room.id);
|
||||
return;
|
||||
}
|
||||
|
||||
games.set(context.room.id, {
|
||||
word: '',
|
||||
vowels: shuffleLetters(availableVowels),
|
||||
consonants: shuffleLetters(availableConsonants),
|
||||
});
|
||||
|
||||
context.sendMessage('Let\'s play the letters! Would you like a consonant or a vowel?', context.room.id);
|
||||
}
|
||||
|
||||
function stop(context) {
|
||||
games.delete(context.room.id);
|
||||
|
||||
context.sendMessage('The game is stopped and reset', context.room.id);
|
||||
}
|
||||
|
||||
function onCommand(args, context) {
|
||||
if (args.subcommand === 'stop') {
|
||||
stop(context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!args.subcommand) {
|
||||
start(context);
|
||||
}
|
||||
}
|
||||
|
||||
function onMessage(message, context) {
|
||||
if (/(^|\b)cons?(onant)?($|\b)/i.test(message.body)) {
|
||||
pickLetter('consonants', context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (/(^|\b)vow(el)?($|\b)/i.test(message.body)) {
|
||||
pickLetter('vowels', context);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
onCommand,
|
||||
onMessage,
|
||||
};
|
|
@ -73,7 +73,7 @@ function play(rawWord, context, shouted) {
|
|||
}
|
||||
|
||||
if (word === mash.anagram) {
|
||||
context.sendMessage(`${config.usernamePrefix}${context.user.username}... :expressionless:`, context.room.id);
|
||||
context.sendMessage(`${config.usernamePrefix}${context.user.username}... ${config.platform === 'schat' ? ':expressionless:' : '😑'}`, context.room.id);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue