Advertisement
AreWe

Dungeonest Dark

Jan 23rd, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. (input) => { // function [ START ]
  2. let health = 100, coins = 0;
  3.  
  4. let rooms = input.shift().split('|');
  5. let len = rooms.length;
  6.  
  7. for(let i=1; i<=len; i++) {
  8. let parts = rooms.shift().split(' ');
  9. let type = parts[0], value = Number(parts[1]);
  10.  
  11. if(type === 'potion') {
  12. let potentialHealth = health + value;
  13. let newHealth = potentialHealth < 100 ? potentialHealth : 100;
  14. console.log(`You healed for ${newHealth-health} hp.`);
  15. health = newHealth;
  16. console.log(`Current health: ${health} hp.`);
  17. } else if(type === 'chest') {
  18. coins += value;
  19. console.log(`You found ${value} coins.`);
  20. } else { // facing a monster
  21. health -= value;
  22. if(health > 0) {
  23. console.log(`You slayed ${type}.`);
  24. } else {
  25. console.log(`You died! Killed by ${type}.`);
  26. console.log(`Best room: ${i}`);
  27. break;
  28. }
  29. }
  30. } // for loop
  31.  
  32. if(health > 0) {
  33. console.log("You've made it!");
  34. console.log(`Coins: ${coins}`);
  35. console.log(`Health: ${health}`);
  36. }
  37. } // function [ END ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement