georgiev955

MU

Jun 9th, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function muOnline(input) {
  2.   let commandArray = input.split("|");
  3.   let health = 100;
  4.   let bitcoin = 0;
  5.   let roomCount = 0;
  6.   let isGameOver = false;
  7.  
  8.   for (let i = 0; i < commandArray.length; i++) {
  9.     let command = commandArray[i].split(" ");
  10.     let action = command[0];
  11.     let value = Number(command[1]);
  12.  
  13.     switch (action) {
  14.       case "potion":
  15.         potion(value);
  16.         break;
  17.       case "chest":
  18.         chest(value);
  19.         break;
  20.       default:
  21.         fight(value);
  22.         break;
  23.     }
  24.  
  25.     function potion(value) {
  26.       if (health > 0) {
  27.         roomCount++;
  28.         if (health + value > 100) {
  29.           console.log(`You healed for ${100 - health} hp.`);
  30.           health = 100;
  31.           console.log(`Current health: ${health} hp.`);
  32.         } else {
  33.           console.log(`You healed for ${value} hp.`);
  34.           health += value;
  35.           console.log(`Current health: ${health} hp.`);
  36.         }
  37.       }
  38.     }
  39.  
  40.     function chest(value) {
  41.       if (health > 0) {
  42.         roomCount++;
  43.         console.log(`You found ${value} bitcoins.`);
  44.         bitcoin += value;
  45.       }
  46.     }
  47.  
  48.     function fight(value) {
  49.       if (health > 0) {
  50.         roomCount++;
  51.         health -= value;
  52.         if (health <= 0) {
  53.           console.log(`You died! Killed by ${action}.`);
  54.           console.log(`Best room: ${roomCount}`);
  55.           isGameOver = true;
  56.         } else {
  57.           console.log(`You slayed ${action}.`);
  58.         }
  59.       }
  60.     }
  61.   }
  62.  
  63.   if (!isGameOver) {
  64.     console.log("You've made it!");
  65.     console.log(`Bitcoins: ${bitcoin}`);
  66.     console.log(`Health: ${health}`);
  67.   }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment