Add Forefeit to tic-tac-toe, Bug Fixes

This commit is contained in:
Dragon Fire
2020-03-17 19:34:14 -04:00
parent d5d2536341
commit 085feae3dc
3 changed files with 11 additions and 6 deletions
+2 -3
View File
@@ -59,12 +59,11 @@ module.exports = class ConnectFourCommand extends Command {
${nums.join('')}
`);
const filter = res => {
if (res.author.id !== user.id) return false
const choice = res.content;
if (choice.toLowerCase() === 'end') return true;
const i = Number.parseInt(choice, 10) - 1;
if (!board[colLevels[i]]) return false;
if (board[colLevels[i]][i] === undefined) return false;
return res.author.id === user.id;
return board[colLevels[i]] && board[colLevels[i]][i] !== undefined;
};
const turn = await msg.channel.awaitMessages(filter, {
max: 1,
+8 -2
View File
@@ -41,7 +41,7 @@ module.exports = class TicTacToeCommand extends Command {
const user = userTurn ? msg.author : opponent;
const sign = userTurn ? 'X' : 'O';
await msg.say(stripIndents`
${user}, which side do you pick?
${user}, which side do you pick? Type \`end\` to forefeit.
\`\`\`
${sides[0]} | ${sides[1]} | ${sides[2]}
—————————
@@ -51,8 +51,10 @@ module.exports = class TicTacToeCommand extends Command {
\`\`\`
`);
const filter = res => {
if (res.author.id !== user.id) return false;
const choice = res.content;
return res.author.id === user.id && sides.includes(choice) && !taken.includes(choice);
if (choice.toLowerCase() === 'end') return true;
return sides.includes(choice) && !taken.includes(choice);
};
const turn = await msg.channel.awaitMessages(filter, {
max: 1,
@@ -64,6 +66,10 @@ module.exports = class TicTacToeCommand extends Command {
continue;
}
const choice = turn.first().content;
if (choice.toLowerCase() === 'end') {
winner = userTurn ? opponent : msg.author;
break;
}
sides[Number.parseInt(choice, 10) - 1] = sign;
taken.push(choice);
if (this.verifyWin(sides)) winner = userTurn ? msg.author : opponent;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "112.9.0",
"version": "112.9.1",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {