This commit is contained in:
Daniel Odendahl Jr
2017-06-14 01:35:09 +00:00
parent d82e17db80
commit 68ca766b36
+13 -4
View File
@@ -8,11 +8,16 @@ module.exports = class HangmanCommand extends Command {
name: 'hangman', name: 'hangman',
group: 'games', group: 'games',
memberName: 'hangman', memberName: 'hangman',
description: 'Play a game of hangman.' description: 'Play a game of hangman.',
guildOnly: true
}); });
this.playing = new Set();
} }
async run(msg) { async run(msg) {
if (this.playing.includes(msg.guild.id)) return msg.say('Only one game may be occurring per server.');
this.playing.add(msg.guild.id);
const word = words[Math.floor(Math.random() * words.length)]; const word = words[Math.floor(Math.random() * words.length)];
let points = 0; let points = 0;
const confirmation = []; const confirmation = [];
@@ -41,15 +46,19 @@ module.exports = class HangmanCommand extends Command {
} else if (word.includes(choice)) { } else if (word.includes(choice)) {
await msg.say('Nice job!'); await msg.say('Nice job!');
confirmation.push(choice); confirmation.push(choice);
for (const letter of word.split('')) { let results = word.split('');
if (letter !== choice) continue; for (let i = 0; i > results.length; i++) {
else display[word.indexOf(letter)] = choice; if (word[i] === choice) {
results[i] = '';
display[i] = word[i];
}
} }
} else { } else {
await msg.say('Nope!'); await msg.say('Nope!');
points++; points++;
} }
} }
this.playing.delete(msg.guild.id);
if (word.length === confirmation.length) return msg.say(`You won, it was ${word}!`); if (word.length === confirmation.length) return msg.say(`You won, it was ${word}!`);
else return msg.say(`Too bad... It was ${word}...`); else return msg.say(`Too bad... It was ${word}...`);
} }