Advertisement
Guest User

DungeonestDark

a guest
Sep 5th, 2020
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve([string]) {
  2.     let mainIndex = 0;
  3.     let insideIndex = 0;
  4.     let word = '';
  5.     let array = [];
  6.     let counter = 0;
  7.  
  8.     while (mainIndex < string.length) {
  9.         for (let i = mainIndex; i < string.length; i++) {
  10.             let letter = string[i];
  11.             if (letter !== ' ' && letter !== '|') {
  12.                 word += letter;
  13.             } else {
  14.                 break;
  15.             }
  16.             counter++;
  17.         }
  18.         array.push(word);
  19.         counter++;
  20.         mainIndex = counter;
  21.         word = '';
  22.     }
  23.  
  24.     let indexArray = 0;
  25.     let health = 100;
  26.     let coins = 0;
  27.     let room = 1;
  28.     let isDead = false;
  29.  
  30.     while (indexArray < array.length) {
  31.         let itemOrMonster = array[indexArray];
  32.         indexArray++;
  33.         let number = Number(array[indexArray]);
  34.         if (itemOrMonster == 'potion') {
  35.             health += number;
  36.             if (health > 100) {
  37.                 number = 100 - (health - number);
  38.                 health = 100;
  39.             }
  40.             console.log(`You healed for ${number} hp.`);
  41.             console.log(`Current health: ${health} hp.`);
  42.         } else if (itemOrMonster == 'chest') {
  43.             coins += number;
  44.             console.log(`You found ${number} coins.`);
  45.         } else {
  46.             health -= number;
  47.             if (health <= 0) {
  48.                 console.log(`You died! Killed by ${itemOrMonster}.`);
  49.                 console.log(`Best room: ${room}`);
  50.                 isDead = true;
  51.                 break;
  52.             } else if (health > 0) {
  53.                 console.log(`You slayed ${itemOrMonster}.`);
  54.             }
  55.         }
  56.         room++;
  57.         indexArray++;
  58.     }
  59.  
  60.     if (isDead == false) {
  61.         console.log(`You've made it!`);
  62.        console.log(`Coins: ${coins}`);
  63.        console.log(`Health: ${health}`);
  64.    }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement