Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. const commando = require('discord.js-commando')
  2. const Discord = require('discord.js');
  3.  
  4. class tttCommand extends commando.Command {
  5. constructor(client) {
  6. super(client, {
  7. name: 'ttt',
  8. group: 'games',
  9. memberName: 'ttt',
  10. description: 'Play a game of Tic-Tac-Toe!',
  11. examples: ['!ttt [move]'],
  12. args: [
  13. {
  14. key: 'player',
  15. prompt: 'You need to specify a player to play with!',
  16. type: 'string',
  17. }
  18. ]
  19. });
  20. }
  21.  
  22.  
  23. async run(message, args) {
  24. try {
  25. const client = this.client;
  26.  
  27. let player1 = message.author
  28. let player2 = message.mentions.users.first()
  29.  
  30. let l1 = "-";
  31. let l2 = "-";
  32. let l3 = "-";
  33. let c1 = "-";
  34. let c2 = "-";
  35. let c3 = "-";
  36. let r1 = "-";
  37. let r2 = "-";
  38. let r3 = "-";
  39.  
  40. message.channel.send({embed: {
  41. color: 0x00AE86,
  42. title: "***Tic-Tac-Toe***",
  43. description: "***" + player1.username + "*** VS ***" + player2.username + "***",
  44. fields: [{
  45. name: "Left 1",
  46. inline: true,
  47. value: l1
  48. },
  49. {
  50. name: "Center 1",
  51. inline: true,
  52. value: c1
  53. },
  54. {
  55. name: "Right 1",
  56. inline: true,
  57. value: r1
  58. },
  59. {
  60. name: "Left 2",
  61. inline: true,
  62. value: l2
  63. },
  64. {
  65. name: "Center 2",
  66. inline: true,
  67. value: c2
  68. },
  69. {
  70. name: "Right 2",
  71. inline: true,
  72. value: r2
  73. },
  74. {
  75. name: "Left 3",
  76. inline: true,
  77. value: l3
  78. },
  79. {
  80. name: "Center 3",
  81. inline: true,
  82. value: c3
  83. },
  84. {
  85. name: "Right 3",
  86. inline: true,
  87. value: r3
  88. }
  89. ],
  90. timestamp: new Date(),
  91. footer: {
  92. icon_url: client.user.avatarURL,
  93. text: "AccuBot"
  94. }
  95. }
  96. })
  97. .then(message => console.log("Test"))
  98. .catch(console.error);
  99.  
  100.  
  101. let player1Won = false;
  102. let player2Won = false;
  103.  
  104. while(player1Won === false || player2Won === false){
  105. const filter = m => m.content.startsWith('l') || m.content.startsWith('c') || m.content.startsWith('r');
  106. message.channel.awaitMessages(filter, { max: 1})
  107. .then(collected => {
  108.  
  109. let move = player1.lastMessage.content
  110.  
  111. switch (move) {
  112. case "l1":
  113. l1 = "O"
  114. break;
  115. case "l2":
  116. l2 = "O"
  117. break;
  118. case "l3":
  119. l3 = "O"
  120. break;
  121. case "c1":
  122. c1 = "O"
  123. break;
  124. case "c2":
  125. c2 = "O"
  126. break;
  127. case "c3":
  128. c3 = "O"
  129. break;
  130. case "r1":
  131. r1 = "O"
  132. break;
  133. case "r2":
  134. r2 = "O"
  135. break;
  136. case "r3":
  137. r3 = "O"
  138. break;
  139. }
  140.  
  141. client.user.lastMessage.edit(
  142. {embed: {
  143. color: 0x00AE86,
  144. title: "***Tic-Tac-Toe***",
  145. description: "***" + player1.username + "*** VS ***" + player2.username + "***",
  146. fields: [{
  147. name: "Left 1",
  148. inline: true,
  149. value: l1
  150. },
  151. {
  152. name: "Center 1",
  153. inline: true,
  154. value: c1
  155. },
  156. {
  157. name: "Right 1",
  158. inline: true,
  159. value: r1
  160. },
  161. {
  162. name: "Left 2",
  163. inline: true,
  164. value: l2
  165. },
  166. {
  167. name: "Center 2",
  168. inline: true,
  169. value: c2
  170. },
  171. {
  172. name: "Right 2",
  173. inline: true,
  174. value: r2
  175. },
  176. {
  177. name: "Left 3",
  178. inline: true,
  179. value: l3
  180. },
  181. {
  182. name: "Center 3",
  183. inline: true,
  184. value: c3
  185. },
  186. {
  187. name: "Right 3",
  188. inline: true,
  189. value: r3
  190. }
  191. ],
  192. timestamp: new Date(),
  193. footer: {
  194. icon_url: client.user.avatarURL,
  195. text: "AccuBot"
  196. }
  197. }
  198. })
  199.  
  200. if (l1 && l2 && l3 === 'O') {
  201. player1Won = true;
  202. } else if (c1 && c2 && c3 === "O") {
  203. player1Won = true;
  204. } else if (r1 && r2 && r3 === "O") {
  205. player1Won = true;
  206. } else if (l1 && c1 && r1 === "O") {
  207. player1Won = true;
  208. } else if (l2 && c2 && r2 === "O") {
  209. player1Won = true;
  210. } else if (l3 && c3 && r3 === "O") {
  211. player1Won = true;
  212. } else {
  213. player1Won = false;
  214. return;
  215. }
  216.  
  217. if (l1 && l2 && l3 === 'X') {
  218. player2Won = true;
  219. } else if (c1 && c2 && c3 === "X") {
  220. player2Won = true;
  221. } else if (r1 && r2 && r3 === "X") {
  222. player2Won = true;
  223. } else if (l1 && c1 && r1 === "X") {
  224. player2Won = true;
  225. } else if (l2 && c2 && r2 === "X") {
  226. player2Won = true;
  227. } else if (l3 && c3 && r3 === "X") {
  228. player2Won = true;
  229. } else {
  230. player2Won = false;
  231. return;
  232. }
  233. })
  234. .catch(() =>{
  235. message.channel.send("No Choice Given.");
  236. return;
  237. });
  238. }
  239. } catch (e) {
  240. console.log(e.stack);
  241. }
  242. }
  243. }
  244.  
  245. module.exports = tttCommand;
  246. process.on("unhandledRejection", console.error)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement