petarkobakov

Heroes of Code and Logic VII

Aug 1st, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection.Metadata;
  5.  
  6. namespace Heroes_of_Code_and_Logic_VII
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int n = int.Parse(Console.ReadLine());
  13. Dictionary<string, List<int>> heroes = new Dictionary<string, List<int>>();
  14.  
  15. for (int i = 0; i < n; i++)
  16. {
  17. string input = Console.ReadLine();
  18. string[] heroData = input.Split();
  19.  
  20. string name = heroData[0];
  21. int HP = int.Parse(heroData[1]);
  22. int MP = int.Parse(heroData[2]);
  23.  
  24. heroes.Add(name, new List<int> { HP, MP });
  25. }
  26.  
  27. string command = Console.ReadLine();
  28.  
  29. while (command != "End")
  30. {
  31. string[] elements = command.Split(" - ", StringSplitOptions.RemoveEmptyEntries);
  32. string action = elements[0];
  33.  
  34.  
  35.  
  36. if (action == "CastSpell")
  37. {
  38. string name = elements[1];
  39. int points = int.Parse(elements[2]);
  40. string castSpell = elements[3];
  41.  
  42.  
  43.  
  44. if (heroes[name][1] - points >= 0)
  45. {
  46. heroes[name][1] -= points;
  47. Console.WriteLine($"{name} has successfully cast {castSpell} and now has {heroes[name][1]} MP!");
  48. }
  49.  
  50. else
  51. {
  52. Console.WriteLine($"{name} does not have enough MP to cast {castSpell}!");
  53. }
  54.  
  55. }
  56.  
  57. else if (action == "TakeDamage")
  58. {
  59. string name = elements[1];
  60. int damage = int.Parse(elements[2]);
  61. string attacker = elements[3];
  62.  
  63.  
  64. heroes[name][0] -= damage;
  65.  
  66. if (heroes[name][0] > 0)
  67. {
  68. Console.WriteLine($"{name} was hit for {damage} HP by {attacker} and now has {heroes[name][0]} HP left!");
  69. }
  70.  
  71. else
  72. {
  73. Console.WriteLine($"{name} has been killed by {attacker}!");
  74. heroes.Remove(name);
  75. }
  76.  
  77. }
  78. else if (action == "Recharge")
  79. {
  80. string name = elements[1];
  81. int amount = int.Parse(elements[2]);
  82.  
  83. if (heroes[name][1] + amount > 200)
  84. {
  85.  
  86. amount = 200 - heroes[name][1];
  87.  
  88.  
  89. }
  90. Console.WriteLine($"{name} recharged for {amount} MP!");
  91. heroes[name][1]+= amount;
  92. }
  93.  
  94. else if (action == "Heal")
  95. {
  96. string name = elements[1];
  97. int amount = int.Parse(elements[2]);
  98.  
  99. if (heroes[name][0] + amount > 100)
  100. {
  101. amount = 100 - heroes[name][0];
  102. }
  103.  
  104. heroes[name][0] += amount;
  105. Console.WriteLine($"{name} healed for {amount} HP!");
  106. }
  107.  
  108. command = Console.ReadLine();
  109. }
  110.  
  111. var sorted = heroes.OrderByDescending(h => h.Value[0]).ThenBy(h=>h.Key);
  112.  
  113. foreach (var hero in sorted)
  114. {
  115. Console.WriteLine(hero.Key);
  116. Console.WriteLine($" HP: {hero.Value[0]}");
  117. Console.WriteLine($" MP: {hero.Value[1]}");
  118. }
  119.  
  120. }
  121. }a
  122. }
  123.  
Advertisement
Add Comment
Please, Sign In to add comment