vasil-y-vasilev

MuOnline

Jul 3rd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function muOnline(input) {
  2.     // Input
  3.     let isAlive = true;
  4.     let dungeons = input.split('|');
  5.     let health = 100;
  6.     let coins = 0;
  7.     let currentDungeon = 0;
  8.  
  9.     // Calculate
  10.     for (const dungeon of dungeons) {
  11.         let [command, value] = dungeon.split(' ');
  12.         value = Number(value);
  13.         currentDungeon++;
  14.  
  15.         if (command == 'potion') {
  16.             let healedWith = value;
  17.  
  18.             if (health + value > 100) {
  19.                 healedWith = 100 - health;
  20.                 health = 100;
  21.             } else {
  22.                 health += value;
  23.             }
  24.  
  25.             console.log(`You healed for ${healedWith} hp.`); // TODO: Fix drama
  26.             console.log(`Current health: ${health} hp.`);
  27.         } else if (command == 'chest') {
  28.             coins += value;
  29.             console.log(`You found ${value} bitcoins.`);
  30.         } else {
  31.             health -= value;
  32.            
  33.             // TODO: if lower or equal than zero
  34.             if (health <= 0) {
  35.                 console.log(`You died! Killed by ${command}.`);
  36.                 console.log(`Best room: ${currentDungeon}`);
  37.                 isAlive = false;
  38.                 break;
  39.             }
  40.  
  41.             console.log(`You slayed ${command}.`);
  42.         }
  43.     }
  44.  
  45.     if (isAlive) {
  46.         console.log("You've made it!");
  47.         console.log(`Bitcoins: ${coins}`);
  48.         console.log(`Health: ${health}`);
  49.     }
  50. }
  51.  
  52. muOnline('rat 10|bat 20|potion 10|rat 10|chest 100|boss 70|chest 1000');
Advertisement
Add Comment
Please, Sign In to add comment