Advertisement
BitCodeBot

Untitled

Apr 30th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. var emojis = ['1⃣', '2⃣', '3⃣', '4⃣', '5⃣', '6⃣', '7⃣', '8⃣', '9⃣'];
  2. function tabu(casas) {
  3. let retorn = ''
  4. for (var i = 0; i < 9; i++) {
  5. retorn += casas[i] ? casas[i] == 1 ? ':x:' : ':o:' : `${emojis[i]}`
  6. retorn += (i == 2 || i == 5) ? '\n' : ''
  7. }
  8. return retorn;
  9. }
  10. function g(casas) {
  11. for (var i = 1; i < 3; i++) {
  12. 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)
  13. || (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) ||
  14. (casas[0] == i && casas[4] == i && casas[8] == i) || (casas[2] == i && casas[4] == i && casas[6] == i)
  15. ) return i;
  16. else if (casas[0] && casas[1] && casas[2] && casas[3] && casas[4] && casas[5] && casas[6] && casas[7] && casas[8]) return 3;
  17. }
  18. return null;
  19. }
  20. class jogo {
  21. constructor(p1, p2) {
  22. this.casas = []
  23. this.x = p1
  24. this.o = p2
  25. this.turn = this.x
  26. this.embed = `:hash::x:` + '\n\n' + tabu(this.casas)
  27. }
  28. jogar(casa) {
  29. if (this.casas[casa]) return null;
  30. this.casas[casa] = this.turn == this.x ? 1 : 2
  31. this.turn = this.turn == this.x ? this.o : this.x
  32. this.embed = `:hash:${this.turn == this.o ? ':o:' : ':x:'}\n\n` + tabu(this.casas)
  33. let venceu = g(this.casas)
  34. if (venceu) {
  35. this.embed = `:crown: ${venceu == 1 ? ':x:' : venceu == 3 ? ':no_good:' : ':o:'}\n\n` + tabu(this.casas)
  36. return 'g';
  37. }
  38. return true;
  39. }
  40. jogarBot(casa) {
  41. if (this.casas[casa]) return null;
  42. this.casas[casa] = 1
  43. let a = () => {
  44. let numero = Math.floor(Math.random() * 9)
  45. this.casas[numero] ? a() : this.casas[numero] = 2
  46. }; a()
  47. this.embed = `:hash::x:\n\n` + tabu(this.casas)
  48. let venceu = g(this.casas)
  49. if (venceu) {
  50. this.embed = `:crown: ${venceu == 1 ? ':x:' : venceu == 3 ? ':no_good:' : ':o:'}\n\n` + tabu(this.casas)
  51. return 'g';
  52. }
  53. }
  54. }
  55.  
  56. exports.run = async(client,message,args) => {
  57. if (!message.mentions.users.first()) return message.reply("Mencione alguem")
  58. if (message.mentions.users.first().id == message.author.id || (message.mentions.users.first().id != client.user.id && message.mentions.users.first().bot)) return;
  59. let main = new jogo(message.author, message.mentions.users.first())
  60. let msg = await message.channel.send(main.embed)
  61. for (var i = 0; i < emojis.length; i++) { await msg.react(emojis[i]) }
  62. let _this = this;
  63. 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 })
  64. col.on('collect', r => {
  65. if (r.users.last().id != main.turn.id) return;
  66. r.remove(main.turn) && r.remove(client.user);
  67. 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();
  68. msg.edit(main.embed)
  69. })
  70. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement