Teo_Yanchev

C# Fundamentals - 02. MuOnline - MidExam 29.02.2020 G1

Oct 27th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _02._MuOnline
  4. {
  5. class MuOnline
  6. {
  7. static void Main()
  8. {
  9. int health = 100;
  10. int bitcoins = 0;
  11. int countRooms = 0;
  12.  
  13. string[] rooms = Console.ReadLine()
  14. .Split('|');
  15.  
  16. for (int i = 0; i < rooms.Length; i++)
  17. {
  18. countRooms += 1;
  19. string[] currentRoom = rooms[i].Split();
  20. string creatureOrLoot = currentRoom[0];
  21. int number = int.Parse(currentRoom[1]);
  22.  
  23. if (creatureOrLoot == "potion" || creatureOrLoot == "chest")
  24. {
  25. if (creatureOrLoot == "potion")
  26. {
  27. if (health == 100)
  28. {
  29. Console.WriteLine("You healed for 0 hp.");
  30. Console.WriteLine($"Current health: {health} hp.");
  31. }
  32.  
  33. else if (health < 100)
  34. {
  35. int oldHealth = health;
  36. health += number;
  37. if (health > 100)
  38. {
  39. health = 100;
  40. int healed = health - oldHealth;
  41. Console.WriteLine($"You healed for {healed} hp.");
  42. Console.WriteLine($"Current health: {health} hp.");
  43. }
  44.  
  45. else
  46. {
  47. Console.WriteLine($"You healed for {number} hp.");
  48. Console.WriteLine($"Current health: {health} hp.");
  49. }
  50. }
  51. }
  52. else
  53. {
  54. bitcoins += number;
  55. Console.WriteLine($"You found {number} bitcoins.");
  56. }
  57. }
  58.  
  59. else
  60. {
  61. health -= number;
  62. if (health > 0)
  63. {
  64. Console.WriteLine($"You slayed {creatureOrLoot}.");
  65. }
  66.  
  67. else
  68. {
  69. Console.WriteLine($"You died! Killed by {creatureOrLoot}.");
  70. Console.WriteLine($"Best room: {countRooms}");
  71. return;
  72. }
  73. }
  74. }
  75.  
  76. Console.WriteLine("You've made it!");
  77. Console.WriteLine($"Bitcoins: {bitcoins}");
  78. Console.WriteLine($"Health: {health}");
  79. }
  80. }
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment