Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dungeonestDark(string) {
- let health = 100
- let maxHealth = 100
- let coins = 0
- let roomElements = []
- let monster = ""
- let roomContent = string.toString().split('|')
- let roomContentL = roomContent.length
- let isDeath = false
- let roomsPassed = 0
- for (let i = 0; i < roomContentL; i++) {
- if (isDeath === true) {
- console.log(`You died! Killed by ${monster}.`)
- console.log(`Best room: ${roomsPassed}`);
- return
- }
- roomElements[i] = roomContent[i].toString().split(' ')
- for (let j = 0; j < 2; j += 2) {
- switch (roomElements[i][j]) {
- case "potion":
- let potion = Number(roomElements[i][j + 1])
- if (health + potion > 100) {
- console.log(`You healed for ${maxHealth - health} hp.`);
- health = 100;
- } else {
- console.log(`You healed for ${potion} hp.`);
- health += potion
- }
- console.log(`Current health: ${health} hp.`);
- break;
- case "chest":
- console.log(`You found ${roomElements[i][j + 1]} coins.`);
- coins += Number(roomElements[i][j + 1]);
- break;
- default:
- monster = roomElements[i][j]
- health -= roomElements[i][j + 1]
- if (health <= 0) {
- isDeath = true
- } else {
- console.log(`You slayed ${monster}.`);
- }
- break;
- }
- roomsPassed++
- }
- }
- if (isDeath === false) {
- console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`)
- }
- }
- dungeonestDark(["cat 10|potion 30|orc 10|chest 10|snake 25|chest 110"])
Advertisement
Add Comment
Please, Sign In to add comment