Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var emojis = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣'];
- function tabu(casas) {
- let retorn = ''
- for (var i = 0; i < 9; i++) {
- retorn += casas[i] ? casas[i] == 1 ? ':x:' : ':o:' : `${emojis[i]}`
- retorn += (i == 2 || i == 5) ? '\n' : ''
- }
- return retorn;
- }
- function g(casas) {
- for (var i = 1; i < 3; i++) {
- if ((casas[0] == i && casas[1] == i && casas[2] == i) || (casas[3] == i && casas[4] == i && casas[5] == i) || (casas[6] == i && casas[7] == i && casas[8] == i)
- || (casas[0] == i && casas[3] == i && casas[6] == i) || (casas[1] == i && casas[4] == i && casas[7] == i) || (casas[2] == i && casas[5] == i && casas[8] == i) ||
- (casas[0] == i && casas[4] == i && casas[8] == i) || (casas[2] == i && casas[4] == i && casas[6] == i)
- ) return i;
- else if (casas[0] && casas[1] && casas[2] && casas[3] && casas[4] && casas[5] && casas[6] && casas[7] && casas[8]) return 3;
- }
- return null;
- }
- class jogo {
- constructor(p1, p2) {
- this.casas = []
- this.x = p1
- this.o = p2
- this.turn = this.x
- this.embed = `:hash::x:` + '\n\n' + tabu(this.casas)
- }
- jogar(casa) {
- if (this.casas[casa]) return null;
- this.casas[casa] = this.turn == this.x ? 1 : 2
- this.turn = this.turn == this.x ? this.o : this.x
- this.embed = `:hash:${this.turn == this.o ? ':o:' : ':x:'}\n\n` + tabu(this.casas)
- let venceu = g(this.casas)
- if (venceu) {
- this.embed = `:crown: ${venceu == 1 ? ':x:' : venceu == 3 ? ':no_good:' : ':o:'}\n\n` + tabu(this.casas)
- return 'g';
- }
- return true;
- }
- jogarBot(casa) {
- if (this.casas[casa]) return null;
- this.casas[casa] = 1
- let a = () => {
- let numero = Math.floor(Math.random() * 9)
- this.casas[numero] ? a() : this.casas[numero] = 2
- }; a()
- this.embed = `:hash::x:\n\n` + tabu(this.casas)
- let venceu = g(this.casas)
- if (venceu) {
- this.embed = `:crown: ${venceu == 1 ? ':x:' : venceu == 3 ? ':no_good:' : ':o:'}\n\n` + tabu(this.casas)
- return 'g';
- }
- }
- }
- exports.run = async(client,message,args) => {
- if (!message.mentions.users.first()) return message.reply("Mencione alguem")
- if (message.mentions.users.first().id == message.author.id || (message.mentions.users.first().id != client.user.id && message.mentions.users.first().bot)) return;
- let main = new jogo(message.author, message.mentions.users.first())
- let msg = await message.channel.send(main.embed)
- for (var i = 0; i < emojis.length; i++) { await msg.react(emojis[i]) }
- let _this = this;
- let col = msg.createReactionCollector((r, u) => emojis.includes(r.emoji.name) && (u.id == message.author.id || u.id == message.mentions.users.first().id || u.id == client.user.id), { time: 1000 * 60 * 10 })
- col.on('collect', r => {
- if (r.users.last().id != main.turn.id) return;
- r.remove(main.turn) && r.remove(client.user);
- if (message.mentions.users.first().id == client.user.id ? main.jogarBot(emojis.indexOf(r.emoji.name)) : main.jogar(emojis.indexOf(r.emoji.name)) == 'g') col.stop();
- msg.edit(main.embed)
- })
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement