vikkktor

Dungeonest-temp

Oct 23rd, 2021
558
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dungeonestDark(string) {
  2.     let health = 100
  3.     let maxHealth = 100
  4.     let coins = 0
  5.     let roomElements = []
  6.     let monster = ""
  7.  
  8.     let roomContent = string.toString().split('|')
  9.     let roomContentL = roomContent.length
  10.     let isDeath = false
  11.     let roomsPassed = 0
  12.  
  13.  
  14.  
  15.     for (let i = 0; i < roomContentL; i++) {
  16.         if (isDeath === true) {
  17.             console.log(`You died! Killed by ${monster}.`)
  18.             console.log(`Best room: ${roomsPassed}`);
  19.             return
  20.         }
  21.         roomElements[i] = roomContent[i].toString().split(' ')
  22.  
  23.         for (let j = 0; j < 2; j += 2) {
  24.             switch (roomElements[i][j]) {
  25.                 case "potion":
  26.                     let potion = Number(roomElements[i][j + 1])
  27.                     if (health + potion > 100) {
  28.                         console.log(`You healed for ${maxHealth - health} hp.`);
  29.                         health = 100;
  30.                     } else {
  31.                         console.log(`You healed for ${potion} hp.`);
  32.                         health += potion
  33.                     }
  34.  
  35.                     console.log(`Current health: ${health} hp.`);
  36.                     break;
  37.                 case "chest":
  38.                     console.log(`You found ${roomElements[i][j + 1]} coins.`);
  39.                     coins += Number(roomElements[i][j + 1]);
  40.                     break;
  41.                 default:
  42.                     monster = roomElements[i][j]
  43.                     health -= roomElements[i][j + 1]
  44.                     if (health <= 0) {
  45.                         isDeath = true
  46.                     } else {
  47.                         console.log(`You slayed ${monster}.`);
  48.                     }
  49.                     break;
  50.             }
  51.             roomsPassed++
  52.         }
  53.     }
  54.     if (isDeath === false) {
  55.         console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`)
  56.    }
  57.  
  58. }
  59.  
  60. dungeonestDark(["cat 10|potion 30|orc 10|chest 10|snake 25|chest 110"])
RAW Paste Data