Better looking tic-tac-toe

This commit is contained in:
Dragon Fire
2021-01-09 18:23:07 -05:00
parent 8defe46be0
commit 0945252b72
3 changed files with 20 additions and 9 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ const { stripIndents } = require('common-tags');
const { verify, list } = require('../../util/Util');
const { LOADING_EMOJI_ID } = process.env;
const blankEmoji = '⚪';
const nums = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣'];
const nums = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣'];
const colors = require('../../assets/json/connect-four');
colors.loading = `<a:loading:${LOADING_EMOJI_ID}>`;
+18 -7
View File
@@ -2,6 +2,7 @@ const Command = require('../../structures/Command');
const tictactoe = require('tictactoe-minimax-ai');
const { stripIndents } = require('common-tags');
const { verify } = require('../../util/Util');
const nums = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣'];
module.exports = class TicTacToeCommand extends Command {
constructor(client) {
@@ -48,13 +49,8 @@ module.exports = class TicTacToeCommand extends Command {
} else {
await msg.say(stripIndents`
${user}, which side do you pick? Type \`end\` to forefeit.
\`\`\`
${sides[0]} | ${sides[1]} | ${sides[2]}
—————————
${sides[3]} | ${sides[4]} | ${sides[5]}
—————————
${sides[6]} | ${sides[7]} | ${sides[8]}
\`\`\`
${this.displayBoard(sides)}
`);
const filter = res => {
if (res.author.id !== user.id) return false;
@@ -119,4 +115,19 @@ module.exports = class TicTacToeCommand extends Command {
}
return newBoard;
}
displayBoard(board) {
let str = '';
for (let i = 0; i < board.length; i++) {
if (board[i] === 'X') {
str += '❌';
} else if (board[i] === 'O') {
str += '⭕';
} else {
str += nums[i];
}
if (i % 3 === 2) str += '\n';
}
return str;
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "124.5.4",
"version": "124.5.5",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {