Advertisement
osman1997

Problem 3. Heroes of Code and Logic VII

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