Advertisement
Guest User

Untitled

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