AreWe

DungeonestDarkk

Jun 8th, 2020
1,031
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. dungeonestDark = ([dungeon]) => {
  2.     dungeon = dungeon.split('|').map(room => {
  3.         let [ type, value ] = room.split(' ');
  4.         return { type, value: Number(value) };
  5.     });
  6.     let health = 100, coins = 0;
  7.     for(let i=0; i<dungeon.length; i++) {
  8.         let { type, value } = dungeon[i];
  9.         if(type === 'potion') {
  10.             let newHealth = (health + value > 100 ? 100 : health + value);
  11.             console.log(`You healed for ${newHealth-health} hp.`);
  12.             health = newHealth;
  13.             console.log(`Current health: ${health} hp.`);
  14.         } else if(type === 'chest') {
  15.             console.log(`You found ${value} coins.`);
  16.             coins += value;
  17.         } else { // monster
  18.             health -= value;
  19.             if(health > 0) console.log(`You slayed ${type}.`);
  20.             else return console.log(`You died! Killed by ${type}.\nBest room: ${i+1}`);
  21.         }
  22.     }
  23.     console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment