Advertisement
Guest User

Untitled

a guest
Aug 14th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. function muOnline(inputArr) {
  2. let copyArr = inputArr[0].slice().split('|');
  3.  
  4. let maxHealth = 100;
  5. let currentHealth = 100;
  6. let bitcoins = 0;
  7. let isDead = false;
  8. let roomCount = 1;
  9.  
  10. for (let i = 0; i < copyArr.length; i++) {
  11. let currentRoom = copyArr[i].slice().split(' ');
  12. let action = currentRoom[0];
  13. let num = Number(currentRoom[1]);
  14.  
  15. if (isDead) {
  16. break;
  17. }
  18.  
  19. switch (action) {
  20. case 'potion':
  21. potion(num)
  22. break;
  23. case 'chest':
  24. chest(num)
  25. break;
  26. default:
  27. figth(action, num)
  28. break;
  29. }
  30. roomCount++
  31. }
  32.  
  33. if (!isDead) {
  34. console.log(`You've made it!\nBitcoins: ${bitcoins}\nHealth: ${currentHealth}`);
  35. }
  36.  
  37. function potion(health) {
  38. if (currentHealth + health <= 100) {
  39. currentHealth += health;
  40. console.log(`You healed for ${health} hp.`);
  41. } else {
  42. console.log(`You healed for ${maxHealth - currentHealth} hp.`);
  43. currentHealth = maxHealth;
  44. }
  45. console.log(`Current health: ${currentHealth} hp.`);
  46. }
  47.  
  48. function chest(bitcoin) {
  49. bitcoins += bitcoin;
  50. console.log(`You found ${bitcoin} bitcoins.`);
  51. }
  52.  
  53. function figth(monster, attack) {
  54. currentHealth -= attack;
  55. if (currentHealth <= 0) {
  56. isDead = true;
  57. console.log(`You died! Killed by ${monster}.`);
  58. console.log(`Best room: ${roomCount}`);
  59. } else {
  60. console.log(`You slayed ${monster}.`);
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement