Advertisement
zarkoy

Untitled

Nov 3rd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02_BakingRush
  6. {
  7. class Program
  8. {
  9. public static void Main()
  10. {
  11. int energy = 100;
  12. int coins = 100;
  13. bool dayCompleted = true;
  14. List<string> dayEvent = Console.ReadLine()
  15. .Split('|', '-')
  16. .ToList();
  17.  
  18.  
  19. for (int i = 0; i <= dayEvent.Count; i++)
  20. {
  21. List<string> command = dayEvent.Take(i).ToList();
  22. if (i > 0)
  23. {
  24. if (command[i - 1] == "rest")
  25. {
  26. int amountToAdd = int.Parse(dayEvent[i]);
  27. if (energy + amountToAdd <= 100)
  28. {
  29. energy += amountToAdd;
  30. Console.WriteLine($"You gained {amountToAdd} energy.");
  31. }
  32. else
  33. {
  34. Console.WriteLine($"You gained 0 energy.");
  35. }
  36. Console.WriteLine($"Current energy: {energy}.");
  37. }
  38. else if (command[i - 1] == "order")
  39. {
  40. int amountToAdd = int.Parse(dayEvent[i]);
  41. if (energy >= 30)
  42. {
  43. energy -= 30;
  44. coins += amountToAdd;
  45. Console.WriteLine($"You earned {amountToAdd} coins.");
  46. }
  47. else
  48. {
  49. energy += 50;
  50. Console.WriteLine($"You had to rest!");
  51. }
  52.  
  53. }
  54. else
  55. {
  56. int number = 0;
  57. bool isNumber = int.TryParse(command[i - 1], out number);
  58. if (!isNumber)
  59. {
  60. int amountToAdd = int.Parse(dayEvent[i]);
  61. coins -= amountToAdd;
  62. if (coins > 0)
  63. {
  64. Console.WriteLine($"You bought {command[i-1]}.");
  65. }
  66. else
  67. {
  68. Console.WriteLine($"Closed! Cannot afford {command[i - 1]}.");
  69. dayCompleted = false;
  70. break;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. if (dayCompleted)
  77. {
  78. Console.WriteLine("Day completed!");
  79. Console.WriteLine($"Coins: {coins}");
  80. Console.WriteLine($"Energy: {energy}");
  81. }
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement