Advertisement
MeliDragon

Untitled

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