Advertisement
dimoBs

02. MuOnline

Feb 21st, 2021
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(array) {
  2.  
  3.     if (typeof array !== 'object') {
  4.         array = [array];
  5.     }
  6.  
  7.     let initialHealth = 100;
  8.     let health = initialHealth;
  9.     let amount = 0;
  10.     let room = 0;
  11.     let copyAraay = array[0].split('|');
  12.     let count = 0;
  13.  
  14.     for (let i = 0; i < copyAraay.length; i++) {
  15.         let command = copyAraay[i].split(' ');
  16.         let [dungeons, points] = command;
  17.         if (health > 0) {
  18.             switch (dungeons) {
  19.                 case 'potion':
  20.                     if (initialHealth >= health + Number(points)) {
  21.                         count++;
  22.                         health += Number(points);
  23.                         room = health;
  24.                         console.log(`You healed for ${points} hp.`);
  25.                         console.log(`Current health: ${health} hp.`);
  26.                     } else {
  27.                         count++
  28.                         console.log(`You healed for ${initialHealth - health} hp.`);
  29.                         health = initialHealth;
  30.                         room = health;
  31.                         console.log(`Current health: ${health} hp.`);
  32.                     }
  33.                     break;
  34.                 case 'chest':
  35.                     count++;
  36.                     amount += Number(points);
  37.                     console.log(`You found ${points} bitcoins.`);
  38.                     break;
  39.                 default:
  40.                     if (health >= 0) {
  41.                         health -= Number(points);
  42.                         if (health > 0) {
  43.                             count++;
  44.                             console.log(`You slayed ${dungeons}.`);
  45.                         } else {
  46.                             console.log(`You died! Killed by ${dungeons}.`);
  47.                             console.log(`Best room: ${i + 1}`);
  48.                         }
  49.                     }
  50.             }
  51.         }
  52.     }
  53.     if (copyAraay.length === count) {
  54.         console.log(`You've made it!\nBitcoins: ${amount}\nHealth: ${health}`);
  55.    }
  56. }
  57. solve('cat 10|potion 30|orc 10|chest 10|snake 25|chest 110');
  58. //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