HristoYonkov

Mu Online

Oct 23rd, 2021
627
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve (array) {
  2.     // Constructing Dungeon string!
  3.     let arr = array.toString();
  4.     let newArray = []; // This array should be used!
  5.     let word = '';
  6.     let index = 0;
  7.     let semiIndex = 1;
  8.  
  9.     for (let el = 0; el <= arr.length; el++) {
  10.         if (semiIndex % 3 === 0) {
  11.             newArray[index] = '|';
  12.             index++;
  13.             semiIndex = 1;
  14.         }
  15.        
  16.         if (arr[el] === ' ' || arr[el] === '|'|| el === arr.length) {
  17.             newArray[index] = word;
  18.             index++;
  19.             semiIndex++;
  20.             word = '';
  21.         } else {
  22.             word += arr[el];
  23.         }
  24.     }
  25.  
  26.     // Walking in dungeon;
  27.     let health = 100;
  28.     let coins = 0;
  29.     let bestRoom = 1;
  30.     let ifMadeIt = true;
  31.  
  32.     for (let element = 0; element < newArray.length; element += 3) {
  33.         let itemMonster = newArray[element];
  34.         let number = newArray[element + 1];
  35.  
  36.             // Potion part
  37.         if (itemMonster === 'potion') {
  38.             let currentHealth = health;
  39.             health += Number(number);
  40.             if (health > 100) {
  41.                 health = 100;
  42.             }
  43.             console.log(`You healed for ${health - currentHealth} hp.`);
  44.             console.log(`Current health: ${health} hp.`);
  45.  
  46.             // Chest part
  47.         } else if (itemMonster === 'chest') {
  48.             coins += Number(number);
  49.             console.log(`You found ${number} bitcoins.`);
  50.  
  51.             // Monster part
  52.         } else {
  53.             health -= Number(number);
  54.             if (health > 0) {
  55.                 console.log(`You slayed ${itemMonster}.`);
  56.             } else {
  57.                 console.log(`You died! Killed by ${itemMonster}.`);
  58.                 ifMadeIt = false;
  59.                 break;
  60.             }
  61.         }
  62.  
  63.         bestRoom++;
  64.     }
  65.  
  66.     if (ifMadeIt) {
  67.         console.log("You've made it!");
  68.         console.log(`Bitcoins: ${coins}`);
  69.         console.log(`Health: ${health}`);
  70.     } else {
  71.         console.log(`Best room: ${bestRoom}`);
  72.     }
  73. }
RAW Paste Data