Dimitar_Mitranov

Untitled

Oct 27th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. namespace P02.BakingRush
  2. {
  3. using System;
  4. using System.Linq;
  5.  
  6. public class BakingRush
  7. {
  8. public static void Main()
  9. {
  10. string[] eventsOfDay = Console.ReadLine().ToLower().Split('|').ToArray();
  11.  
  12. int startingEnergy = 100;
  13. int startingCoins = 100;
  14.  
  15. bool areAllEventsDone = false;
  16.  
  17. for (int currentAction = 0; currentAction < eventsOfDay.Length; currentAction++)
  18. {
  19. string[] currentEvent = eventsOfDay[currentAction].ToLower().Split('-').ToArray();
  20.  
  21. if (currentEvent[0] == "rest")
  22. {
  23. int energyGain = int.Parse(currentEvent[1]);
  24.  
  25. if (startingEnergy == 100)
  26. {
  27. Console.WriteLine("You gained 0 energy.");
  28. Console.WriteLine("Current energy: 100.");
  29. }
  30. else if (startingEnergy < 100 && startingEnergy + energyGain <= 100)
  31. {
  32. startingEnergy += energyGain;
  33. Console.WriteLine($"You gained {energyGain} energy.");
  34. Console.WriteLine($"Current energy: {startingEnergy}.");
  35. }
  36. else if (startingEnergy < 100 && startingEnergy + energyGain > 100)
  37. {
  38. Console.WriteLine($"You gained {100 - startingEnergy} energy.");
  39. Console.WriteLine($"Current energy: 100.");
  40. startingEnergy = 100;
  41. }
  42. }
  43. else if (currentEvent[0] == "order")
  44. {
  45. int coinsGained = int.Parse(currentEvent[1]);
  46.  
  47. if (startingEnergy - 30 >= 0)
  48. {
  49. startingEnergy -= 30;
  50. startingCoins += coinsGained;
  51. Console.WriteLine($"You earned {coinsGained} coins.");
  52. }
  53. else
  54. {
  55. startingEnergy += 50;
  56. Console.WriteLine("You had to rest!");
  57. }
  58. }
  59. else
  60. {
  61. int ingredientCost = int.Parse(currentEvent[1]);
  62.  
  63. if (startingCoins > 0 && startingCoins > ingredientCost)
  64. {
  65. Console.WriteLine($"You bought {currentEvent[0]}.");
  66. startingCoins -= ingredientCost;
  67. }
  68. else
  69. {
  70. Console.WriteLine($"Closed! Cannot afford {currentEvent[0]}.");
  71. break;
  72. }
  73. }
  74.  
  75. if (currentAction == eventsOfDay.Length - 1)
  76. {
  77. areAllEventsDone = true;
  78. }
  79. }
  80.  
  81. if (areAllEventsDone == true)
  82. {
  83. Console.WriteLine($"Day completed!\n" +
  84. $"Coins: {startingCoins}\n" +
  85. $"Energy: {startingEnergy}");
  86. }
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment