Advertisement
desito07

MuOnline

Jun 28th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. function muOnline(arr) {
  2. let online = arr[0].split("|");
  3. // console.log(online);
  4. let health = 100;
  5. let bitcoin = 0;
  6. let allBitcoin = 0;
  7. let roomsCounter = 0;
  8.  
  9. for (let i = 0; i < online.length; i++) {
  10. let element = online[i];
  11. let currentRoom = element.split(" ");
  12. // console.log(currentRoom);
  13. let command = currentRoom[0];
  14. let num = Number(currentRoom[1]);
  15. roomsCounter++;
  16.  
  17. if (command === "potion") {
  18. if (health + num > 100) {
  19. num = 100 - health;
  20. health = 100;
  21. } else {
  22. health += num;
  23. }
  24. console.log(`You healed for ${num} hp.`);
  25. console.log(`Current health: ${health} hp.`);
  26. } else if (command === "chest") {
  27. bitcoin = Number(num);
  28. allBitcoin += bitcoin;
  29. console.log(`You found ${bitcoin} bitcoins.`);
  30. } else {
  31. health -= Number(num);
  32. if (health > 0) {
  33. console.log(`You slayed ${command}.`);
  34. } else {
  35. console.log(`You died! Killed by ${command}.`);
  36. console.log(`Best room: ${roomsCounter}`);
  37. return;
  38. }
  39. }
  40. }
  41. console.log(`You've made it!", "Bitcoins: ${allBitcoin}", "Health: ${health}`);
  42. }
  43. muOnline(['rat 10|bat 20|potion 10|rat 10|chest 100|boss 70|chest 1000']);
  44. muOnline(["cat 10|potion 30|orc 10|chest 10|snake 25|chest 110"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement