mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-06 14:20:51 +02:00
Add Forefeit to tic-tac-toe, Bug Fixes
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "112.9.0",
|
||||
"version": "112.9.1",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user