AreWe

Dungeonest Dark

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