svephoto

MuOnline [JavaScript]

Jul 15th, 2021
1,528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function muOnline(input) {
  2.     let array = input.split("|");
  3.  
  4.     let initialHealth = 100;
  5.     let totalBitcoins = 0;
  6.     let roomCounter = 0;
  7.     let monster = "";
  8.  
  9.     for (let i = 0; i < array.length; i++) {
  10.         let tokens = array[i].split(" ");
  11.  
  12.         if (tokens[0] == "potion") {
  13.             roomCounter++;
  14.          
  15.             let healingPart = Number.parseInt(tokens[1]);
  16.             let currentHealth = initialHealth + healingPart;
  17.          
  18.             if (currentHealth < 100) {
  19.                 initialHealth += healingPart;
  20.                 console.log(`You healed for ${healingPart} hp.`);
  21.                 console.log(`Current health: ${currentHealth} hp.`);
  22.             } else {
  23.                 let potionOfHealingPart = (100 + healingPart) - currentHealth;
  24.                 initialHealth += potionOfHealingPart;
  25.                 console.log(`You healed for ${potionOfHealingPart} hp.`);
  26.                 console.log(`Current health: ${initialHealth} hp.`);
  27.             }
  28.         } else if (tokens[0] == "chest") {
  29.             roomCounter++;
  30.          
  31.             let numberOfBitcoins = Number.parseInt(tokens[1]);
  32.             console.log(`You found ${numberOfBitcoins} bitcoins.`);
  33.          
  34.             totalBitcoins += numberOfBitcoins;
  35.         } else {
  36.             roomCounter++;
  37.  
  38.             monster = tokens[0];
  39.             let attack = Number.parseInt(tokens[1]);
  40.             initialHealth -= attack;
  41.             if (initialHealth > 0) {
  42.                 console.log(`You slayed ${monster}.`);
  43.             } else {
  44.                 console.log(`You died! Killed by ${monster}.`);
  45.                 console.log(`Best room: ${roomCounter}`);
  46.                 return;
  47.             }
  48.         }
  49.     }
  50.  
  51.     console.log(`You've made it!\nBitcoins: ${totalBitcoins}\nHealth: ${initialHealth}`);
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment