Advertisement
dimoBs

02. MuOnline

Jan 26th, 2021
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. function solve(array) {
  2.  
  3. if (typeof array !== 'object') {
  4. array = [array];
  5. }
  6.  
  7. let initialHealth = 100;
  8. let health = initialHealth;
  9. let amount = 0;
  10. let room = 0;
  11. let copyAraay = array[0].split('|');
  12. let count = 0;
  13.  
  14. for (let i = 0; i < copyAraay.length; i++) {
  15. let command = copyAraay[i].split(' ');
  16. let [dungeons, points] = command;
  17. if (health > 0) {
  18. switch (dungeons) {
  19. case 'potion':
  20. count++;
  21. if (initialHealth >= health + Number(points)) {
  22. health += Number(points);
  23. room = health;
  24. console.log(`You healed for ${points} hp.`);
  25. console.log(`Current health: ${health} hp.`);
  26. } else {
  27. count++
  28. console.log(`You healed for ${initialHealth - health} hp.`);
  29. health = initialHealth;
  30. room = health;
  31. console.log(`Current health: ${health} hp.`);
  32. }
  33. break;
  34. case 'chest':
  35. count++;
  36. amount += Number(points);
  37. console.log(`You found ${points} bitcoins.`);
  38. break;
  39. default:
  40. count++;
  41. if (health >= 0) {
  42. health -= Number(points);
  43. if (health > 0) {
  44. console.log(`You slayed ${dungeons}.`);
  45.  
  46. } else {
  47. console.log(`You died! Killed by ${dungeons}.`);
  48. console.log(`Best room: ${i + 1}`);
  49. }
  50. }
  51. }
  52. }
  53. }
  54. if (copyAraay.length + 1 === count) {
  55. console.log(`You've made it!\nBitcoins: ${amount}\nHealth: ${health}`);
  56. }
  57. }
  58. solve('cat 10|potion 30|orc 10|chest 10|snake 25|chest 110');
  59. //solve(['rat 10|bat 20|potion 10|rat 10|chest 100|boss 70|chest 1000']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement