Advertisement
Lulunga

dungeonestDark

Jun 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. function dungeonestDark(parameters) {
  2. let rooms = parameters[0].split('|');
  3. let health = 100;
  4. let coins = 0;
  5.  
  6. for (let i = 0; i < rooms.length; i++) {
  7. let room = rooms[i].split(' ');
  8. let roomContent = room[0];
  9. let roomValue = Number(room[1]);
  10. if (roomContent === 'potion') {
  11. let healthGain = Math.min(roomValue, 100 - health);
  12. health += healthGain;
  13. console.log(`You healed for ${healthGain} hp.\nCurrent health: ${health} hp.`);
  14. } else if (roomContent === 'chest') {
  15. coins += roomValue;
  16. console.log(`You found ${roomValue} coins.`)
  17. } else {
  18. let monsterName = roomContent;
  19. let monsterDamage = roomValue;
  20. health -= monsterDamage;
  21. if (health <= 0) {
  22. console.log(`You died! Killed by ${monsterName}.\nBest room: ${i+1}`)
  23. break;
  24. }
  25. console.log(`You slayed ${monsterName}.`);
  26. }
  27. }
  28. if (health > 0) {
  29. console.log(`You've made it!\nCoins: ${coins}\nHealth: ${health}`)
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement