Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function(message, playing) {
  2.     var lives = 6;
  3.     var drawing = "☐ ☐ ☐ ☐  ⭕⭕⭕⭕\n";
  4.     var comb = "",
  5.       letters = ["Z", "X", "C", "V", "B", "N"];
  6.     for (var i = 0; i < 4; i++) {
  7.       comb += letters[~~(Math.random() * letters.length)];
  8.     }
  9.     message.channel.send(`\`\`\`Počela je igra skočka! Ovo su slova koje možete koristiti: Z, X, C, V, B, N\n\n${drawing.repeat(6)}\`\`\``);
  10.     var resultDr = [],
  11.       over = true;
  12.     const f = m => !m.content.startsWith('!');
  13.     const collect = message.channel.createMessageCollector(f, {
  14.       time: 70000
  15.     })
  16.     collect.on('collect', m => {
  17.       if (!m.content.startsWith("!") && !(m.author.bot) && m.content.length >= 4) {
  18.         var input = m.content.replace(/\s/g, "").substring(0, 4).toUpperCase();
  19.         var inp = input.split("");
  20.         var combination = comb.split("");
  21.         var onSpot = 0, notOnSpot = 0;
  22.         for (var i = 0; i < 4; i++) {
  23.           if (!combination.includes(inp[i])) {
  24.             inp[i] = " ";
  25.           }
  26.           if (combination[i] === inp[i] && inp[i] !== " ") {
  27.             onSpot++;
  28.             inp[i] = " ";
  29.             combination[i] = " ";
  30.           }
  31.         }
  32.         for(var i = 0; i < 4; i++) {
  33.           for (var j = 0; j < 4; j++) {    
  34.             if (j !== i && inp[i] === combination[j] && inp[i] !== " ") {
  35.               combination[j] = " ";
  36.               inp[i] = " ";
  37.               notOnSpot++;
  38.             }
  39.           }
  40.         }
  41.         resultDr.push(input.split("").join("  ") + "  " + "🔴".repeat(onSpot) + "🔵".repeat(notOnSpot) + "⭕".repeat(4 - (onSpot + notOnSpot)) + "\n");
  42.         if (comb === input) {
  43.           message.channel.send(`\`\`\`Pobedio si!\n\n${resultDr.join("")}${drawing.repeat(lives-1)}\n\`\`\``);
  44.           over = false;
  45.           collect.stop();
  46.         }
  47.         if (lives - 1 === 0 && over) {
  48.           message.channel.send(`\`\`\`Izgubio si!\n\n${resultDr.join("")}\nRešenje je bilo: ${comb}\`\`\``);
  49.           over = false;
  50.           collect.stop();
  51.         } else if (over) {
  52.           lives--;
  53.           message.channel.send(`\`\`\`Imaš još ${lives} pokušaj${(lives !== 1) ? "a":""}\n\n${resultDr.join("")}${drawing.repeat(lives)}\`\`\``);
  54.         }
  55.       }
  56.     });
  57.     collect.on('end', collected => {
  58.       if (over) {
  59.         message.channel.send("**Time is up** :stopwatch: rešenje je bilo: `" + comb + "`");
  60.       }
  61.       var ind = playing.findIndex(e => e["serverId"] === message.guild.id);
  62.       playing[ind]["playing"] = false;
  63.     });
  64.   },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement