Advertisement
Guest User

MuOnline

a guest
Apr 30th, 2020
989
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.     let health = 100;
  4.     let bitcoins = 0;
  5.     let notDead = true;
  6.     for (let i = 0; i < rooms.length; i++) {
  7.         let command = rooms[i];
  8.         let splitted = command.split(' ');
  9.         if (splitted[0] === 'potion') {
  10.             let addHealth = Number(splitted[1]);
  11.             let newHealth = (health + addHealth > 100) ? 100 : health + addHealth;
  12.             console.log(`You healed for ${newHealth - health} hp.`);
  13.             health = newHealth;
  14.             console.log(`Current health: ${health} hp.`);
  15.         } else if (splitted[0] == 'chest') {
  16.             bitcoins += Number(splitted[1]);
  17.             console.log(`You found ${splitted[1]} bitcoins.`);
  18.         } else {
  19.             let attack = Number(splitted[1]);
  20.             health -= attack;
  21.             if (health <= 0) {
  22.                 console.log(`You died! Killed by ${splitted[0]}.`);
  23.                 console.log(`Best room: ${i + 1}`);
  24.                 notDead = false;
  25.                 break;
  26.             } else if (health > 0) {
  27.                 console.log(`You slayed ${splitted[0]}.`);
  28.             }
  29.         }
  30.         if (!notDead) {
  31.             break;
  32.         }
  33.     }
  34.     if (notDead) {
  35.         console.log(`You've made it!`);
  36.        console.log(`Bitcoins: ${bitcoins}`);
  37.        console.log(`Health: ${health}`);
  38.    }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement