Advertisement
Spocoman

02. MuOnline

Nov 3rd, 2023
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function muOnline(input) {
  2.     let health = 100, bitcoins = 0;
  3.     var rooms = input.split('|');
  4.  
  5.     for (let i = 0; i < rooms.length; i++) {
  6.         var tokens = rooms[i].split(' ');
  7.         let command = tokens[0];
  8.         let amount = Number(tokens[1]);
  9.  
  10.         if (command == "potion") {
  11.             if (health + amount > 100) {
  12.                 amount = 100 - health;
  13.             }
  14.             health += amount;
  15.             console.log(`You healed for ${amount} hp.\nCurrent health: ${health} hp.`);
  16.         } else if (command == "chest") {
  17.             bitcoins += amount;
  18.             console.log(`You found ${amount} bitcoins.`);
  19.         } else {
  20.             health -= amount;
  21.  
  22.             if (health <= 0) {
  23.                 console.log(`You died! Killed by ${command}.\nBest room: ${i + 1}`);
  24.                 break;
  25.             }
  26.             console.log(`You slayed ${command}.`);
  27.         }
  28.     }
  29.  
  30.     if (health > 0) {
  31.         console.log(`You've made it!\nBitcoins: ${bitcoins}\nHealth: ${health}`);
  32.    }
  33.    return;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement