nikolayneykov

Untitled

Feb 28th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dungeonestDark(arr) {
  2.     let params = arr[0].split('|');
  3.     let health = 100;
  4.     let coins = 0;
  5.     let bestRoom = 0;
  6.  
  7.     for (let element of params) {
  8.         let tokens = element.split(' ');
  9.         let roomMonster = tokens[0];
  10.         let numbers = tokens[1];
  11.  
  12.         for (let i = 0; i < params.length; i++) {
  13.             if (roomMonster === 'potion') {
  14.                 if (health < 100) {
  15.                     bestRoom++;
  16.                     let healthNeed = 100-health;
  17.                     health += Number(numbers);
  18.                     if (health > 100) {
  19.                         let healthHere = (health - 100);
  20.                         health -= healthHere;
  21.                         healthHere = healthHere / 2;
  22.  
  23.                         console.log(`You healed for ${healthNeed} hp.`);
  24.                         console.log(`Current health: ${health} hp.`);
  25.                         break;
  26.                     }
  27.                     console.log(`You healed for ${numbers} hp.`);
  28.                     console.log(`Current health: ${health} hp.`);
  29.                     break;
  30.  
  31.                 } else if (health >= 100) {
  32.                     bestRoom++;
  33.                     break;
  34.                 }
  35.  
  36.             } else if (roomMonster === 'chest') {
  37.                 bestRoom++;
  38.                 let foundCoins = Number(numbers);
  39.                 coins += foundCoins;
  40.                 console.log(`You found ${foundCoins} coins.`);
  41.                 break;
  42.  
  43.             }
  44.             if (roomMonster !== 'chest' && roomMonster !== 'potion') {
  45.                 bestRoom++;
  46.                 if (health - Number(numbers) >0) {
  47.                     health -= Number(numbers);
  48.                     console.log(`You slayed ${roomMonster}.`);
  49.                     break;
  50.  
  51.                 } else {
  52.                     console.log(`You died! Killed by ${roomMonster}.`);
  53.                     console.log(`Best room: ${bestRoom}`);
  54.                     return;
  55.  
  56.                 }
  57.  
  58.             }
  59.  
  60.  
  61.         }
  62.     }
  63.  
  64.  
  65.     console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`)
  66.  
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment