Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function(message, playing) {
- var lives = 6;
- var drawing = "☐ ☐ ☐ ☐ ⭕⭕⭕⭕\n";
- var comb = "",
- letters = ["Z", "X", "C", "V", "B", "N"];
- for (var i = 0; i < 4; i++) {
- comb += letters[~~(Math.random() * letters.length)];
- }
- 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)}\`\`\``);
- var resultDr = [],
- over = true;
- const f = m => !m.content.startsWith('!');
- const collect = message.channel.createMessageCollector(f, {
- time: 70000
- })
- collect.on('collect', m => {
- if (!m.content.startsWith("!") && !(m.author.bot) && m.content.length >= 4) {
- var input = m.content.replace(/\s/g, "").substring(0, 4).toUpperCase();
- var inp = input.split("");
- var combination = comb.split("");
- var onSpot = 0, notOnSpot = 0;
- for (var i = 0; i < 4; i++) {
- if (!combination.includes(inp[i])) {
- inp[i] = " ";
- }
- if (combination[i] === inp[i] && inp[i] !== " ") {
- onSpot++;
- inp[i] = " ";
- combination[i] = " ";
- }
- }
- for(var i = 0; i < 4; i++) {
- for (var j = 0; j < 4; j++) {
- if (j !== i && inp[i] === combination[j] && inp[i] !== " ") {
- combination[j] = " ";
- inp[i] = " ";
- notOnSpot++;
- }
- }
- }
- resultDr.push(input.split("").join(" ") + " " + "🔴".repeat(onSpot) + "🔵".repeat(notOnSpot) + "⭕".repeat(4 - (onSpot + notOnSpot)) + "\n");
- if (comb === input) {
- message.channel.send(`\`\`\`Pobedio si!\n\n${resultDr.join("")}${drawing.repeat(lives-1)}\n\`\`\``);
- over = false;
- collect.stop();
- }
- if (lives - 1 === 0 && over) {
- message.channel.send(`\`\`\`Izgubio si!\n\n${resultDr.join("")}\nRešenje je bilo: ${comb}\`\`\``);
- over = false;
- collect.stop();
- } else if (over) {
- lives--;
- message.channel.send(`\`\`\`Imaš još ${lives} pokušaj${(lives !== 1) ? "a":""}\n\n${resultDr.join("")}${drawing.repeat(lives)}\`\`\``);
- }
- }
- });
- collect.on('end', collected => {
- if (over) {
- message.channel.send("**Time is up** :stopwatch: rešenje je bilo: `" + comb + "`");
- }
- var ind = playing.findIndex(e => e["serverId"] === message.guild.id);
- playing[ind]["playing"] = false;
- });
- },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement