nikolayneykov

Untitled

Feb 28th, 2019
158
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.  
  15.                 let healthGain = Math.min(numbers, 100 - health);
  16.                 health += healthGain;
  17.                 console.log(`You healed for ${healthGain} hp.\nCurrent health: ${health} hp.`);
  18.                 bestRoom++;
  19.                 break;
  20.  
  21.                 // if (health < 100) {
  22.                 //     bestRoom++;
  23.                 //     health += Number(numbers);
  24.                 //     if (health > 100) {
  25.                 //         let healthHere = (health - 100);
  26.                 //         health -= healthHere;
  27.                 //         healthHere = healthHere / 2;
  28.  
  29.                 //         console.log(`You healed for ${healthHere} hp.`);
  30.                 //         console.log(`Current health: ${health} hp.`);
  31.                 //         break;
  32.                 //     }
  33.                 //     console.log(`You healed for ${numbers} hp.`);
  34.                 //     console.log(`Current health: ${health} hp.`);
  35.                 //     break;
  36.  
  37.                 // } else if (health >= 100) {
  38.                 //     bestRoom++;
  39.                 //     break;
  40.                 // }
  41.  
  42.             } else if (roomMonster === 'chest') {
  43.                 bestRoom++;
  44.                 let foundCoins = Number(numbers);
  45.                 coins += foundCoins;
  46.                 console.log(`You found ${foundCoins} coins.`);
  47.                 break;
  48.  
  49.             }
  50.             if (roomMonster !== 'chest' && roomMonster !== 'potion') {
  51.                 bestRoom++;
  52.                 if (health - Number(numbers) >0) {
  53.                     health -= Number(numbers);
  54.                     console.log(`You slayed ${roomMonster}.`);
  55.                     break;
  56.  
  57.                 } else {
  58.                     console.log(`You died! Killed by ${roomMonster}.`);
  59.                     console.log(`Best room: ${bestRoom}`);
  60.                     return;
  61.  
  62.                 }
  63.  
  64.             }
  65.  
  66.  
  67.         }
  68.     }
  69.  
  70.  
  71.     console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`)
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment