Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const commando = require('discord.js-commando')
- const Discord = require('discord.js');
- class tttCommand extends commando.Command {
- constructor(client) {
- super(client, {
- name: 'ttt',
- group: 'games',
- memberName: 'ttt',
- description: 'Play a game of Tic-Tac-Toe!',
- examples: ['!ttt [move]'],
- args: [
- {
- key: 'player',
- prompt: 'You need to specify a player to play with!',
- type: 'string',
- }
- ]
- });
- }
- async run(message, args) {
- try {
- const client = this.client;
- let player1 = message.author
- let player2 = message.mentions.users.first()
- let l1 = "-";
- let l2 = "-";
- let l3 = "-";
- let c1 = "-";
- let c2 = "-";
- let c3 = "-";
- let r1 = "-";
- let r2 = "-";
- let r3 = "-";
- message.channel.send({embed: {
- color: 0x00AE86,
- title: "***Tic-Tac-Toe***",
- description: "***" + player1.username + "*** VS ***" + player2.username + "***",
- fields: [{
- name: "Left 1",
- inline: true,
- value: l1
- },
- {
- name: "Center 1",
- inline: true,
- value: c1
- },
- {
- name: "Right 1",
- inline: true,
- value: r1
- },
- {
- name: "Left 2",
- inline: true,
- value: l2
- },
- {
- name: "Center 2",
- inline: true,
- value: c2
- },
- {
- name: "Right 2",
- inline: true,
- value: r2
- },
- {
- name: "Left 3",
- inline: true,
- value: l3
- },
- {
- name: "Center 3",
- inline: true,
- value: c3
- },
- {
- name: "Right 3",
- inline: true,
- value: r3
- }
- ],
- timestamp: new Date(),
- footer: {
- icon_url: client.user.avatarURL,
- text: "AccuBot"
- }
- }
- })
- .then(message => console.log("Test"))
- .catch(console.error);
- let player1Won = false;
- let player2Won = false;
- while(player1Won === false || player2Won === false){
- const filter = m => m.content.startsWith('l') || m.content.startsWith('c') || m.content.startsWith('r');
- message.channel.awaitMessages(filter, { max: 1})
- .then(collected => {
- let move = player1.lastMessage.content
- switch (move) {
- case "l1":
- l1 = "O"
- break;
- case "l2":
- l2 = "O"
- break;
- case "l3":
- l3 = "O"
- break;
- case "c1":
- c1 = "O"
- break;
- case "c2":
- c2 = "O"
- break;
- case "c3":
- c3 = "O"
- break;
- case "r1":
- r1 = "O"
- break;
- case "r2":
- r2 = "O"
- break;
- case "r3":
- r3 = "O"
- break;
- }
- client.user.lastMessage.edit(
- {embed: {
- color: 0x00AE86,
- title: "***Tic-Tac-Toe***",
- description: "***" + player1.username + "*** VS ***" + player2.username + "***",
- fields: [{
- name: "Left 1",
- inline: true,
- value: l1
- },
- {
- name: "Center 1",
- inline: true,
- value: c1
- },
- {
- name: "Right 1",
- inline: true,
- value: r1
- },
- {
- name: "Left 2",
- inline: true,
- value: l2
- },
- {
- name: "Center 2",
- inline: true,
- value: c2
- },
- {
- name: "Right 2",
- inline: true,
- value: r2
- },
- {
- name: "Left 3",
- inline: true,
- value: l3
- },
- {
- name: "Center 3",
- inline: true,
- value: c3
- },
- {
- name: "Right 3",
- inline: true,
- value: r3
- }
- ],
- timestamp: new Date(),
- footer: {
- icon_url: client.user.avatarURL,
- text: "AccuBot"
- }
- }
- })
- if (l1 && l2 && l3 === 'O') {
- player1Won = true;
- } else if (c1 && c2 && c3 === "O") {
- player1Won = true;
- } else if (r1 && r2 && r3 === "O") {
- player1Won = true;
- } else if (l1 && c1 && r1 === "O") {
- player1Won = true;
- } else if (l2 && c2 && r2 === "O") {
- player1Won = true;
- } else if (l3 && c3 && r3 === "O") {
- player1Won = true;
- } else {
- player1Won = false;
- return;
- }
- if (l1 && l2 && l3 === 'X') {
- player2Won = true;
- } else if (c1 && c2 && c3 === "X") {
- player2Won = true;
- } else if (r1 && r2 && r3 === "X") {
- player2Won = true;
- } else if (l1 && c1 && r1 === "X") {
- player2Won = true;
- } else if (l2 && c2 && r2 === "X") {
- player2Won = true;
- } else if (l3 && c3 && r3 === "X") {
- player2Won = true;
- } else {
- player2Won = false;
- return;
- }
- })
- .catch(() =>{
- message.channel.send("No Choice Given.");
- return;
- });
- }
- } catch (e) {
- console.log(e.stack);
- }
- }
- }
- module.exports = tttCommand;
- process.on("unhandledRejection", console.error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement