Advertisement
dpeeva

MuOnline

Jun 24th, 2022
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let health = 100
  3.     let bitcoins = 0
  4.     const rooms = input.split("|")
  5.     const totalRooms = rooms.length
  6.  
  7.     let room = ""
  8.     let word = ""
  9.     let n = 0
  10.     let roomsVisited = 0
  11.  
  12.     while (rooms.length > 0) {
  13.         roomsVisited++
  14.         room = rooms.shift().split(" ")
  15.         word = room[0]
  16.         n = Number(room[1])
  17.  
  18.         if (word === "potion") {
  19.             health += n
  20.             if (health > 100) {
  21.                 n = n - (health - 100)
  22.                 health = 100
  23.             }
  24.             console.log(`You healed for ${n} hp.`)
  25.             console.log(`Current health: ${health} hp.`)
  26.             continue
  27.         }
  28.         if (word === "chest") {
  29.             bitcoins += n
  30.             console.log(`You found ${n} bitcoins.`)
  31.             continue
  32.         }
  33.  
  34.         health -= n
  35.         if (health > 0) {
  36.             console.log(`You slayed ${word}.`)
  37.         } else {
  38.             console.log(`You died! Killed by ${word}.`)
  39.             console.log(`Best room: ${roomsVisited}`)
  40.             return
  41.         }
  42.  
  43.     }
  44.  
  45.     if (roomsVisited === totalRooms) {
  46.         console.log(`You've made it!`)
  47.        console.log(`Bitcoins: ${bitcoins}`)
  48.        console.log(`Health: ${health}`)
  49.    }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement