Advertisement
Guest User

Untitled

a guest
Dec 10th, 2020
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace test3
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. var myDic = new Dictionary<string, List<int>>();
  13.  
  14. int count = int.Parse(Console.ReadLine());
  15.  
  16. for (int i = 0; i < count; i++)
  17. {
  18. string input = Console.ReadLine();
  19.  
  20. var currInput = input.Split().ToList(); //{hero name} {HP} {MP}
  21.  
  22. string heroName = currInput[0];
  23. int hP = int.Parse(currInput[1]);
  24. int mP = int.Parse(currInput[2]);
  25.  
  26. myDic.Add(heroName, new List<int>(){hP, mP, 0});
  27.  
  28.  
  29. }
  30. string comands;
  31. while ((comands = Console.ReadLine()) != "End")
  32. {
  33. var currCommands = comands.Split(" - ").ToList();
  34.  
  35. string singleComand = currCommands[0];
  36. string currHero = currCommands[1];
  37.  
  38. if (singleComand == "CastSpell") //CastSpell – {hero name} – {MP needed} – {spell name}
  39.  
  40. {
  41. int mPNeeded = int.Parse(currCommands[2]);
  42. string spellName = currCommands[3];
  43. int currmP = myDic[currHero][1];
  44.  
  45. if (mPNeeded > currmP)
  46. {
  47. Console.WriteLine($"{currHero} does not have enough MP to cast {spellName}!");
  48.  
  49.  
  50. }
  51. else
  52. {
  53. Console.WriteLine($"{currHero} has successfully cast {spellName} and now has {currmP - mPNeeded} MP!");
  54.  
  55. myDic[currHero][1] = currmP - mPNeeded;
  56. }
  57.  
  58. }
  59. else if (singleComand == "TakeDamage") //TakeDamage – {hero name} – {damage} – {attacker}
  60.  
  61. {
  62. int damage = int.Parse(currCommands[2]);
  63. string attacker = currCommands[3];
  64. int currHp = myDic[currHero][0];
  65.  
  66. int redused = currHp - damage;
  67. myDic[currHero][0] = redused;
  68.  
  69. if (redused <= 0)
  70. {
  71. Console.WriteLine($"{currHero} has been killed by {attacker}!");
  72.  
  73. myDic.Remove(currHero);
  74.  
  75. }
  76. else
  77. {
  78. Console.WriteLine($"{currHero} was hit for {damage} HP by {attacker} and now has {redused} HP left!");
  79. }
  80.  
  81.  
  82. }
  83. else if (singleComand == "Recharge") //Recharge – {hero name} – {amount}
  84.  
  85. {
  86. int amount = int.Parse(currCommands[2]);
  87. int curMp = myDic[currHero][1];
  88. int lifted = curMp + amount;
  89.  
  90. if (lifted > 200)
  91. {
  92.  
  93. lifted = 200;
  94. Console.WriteLine($"{currHero} recharged for {200 - curMp} MP!");
  95. myDic[currHero][1] = 200;
  96. }
  97. else
  98. {
  99. Console.WriteLine($"{currHero} recharged for {lifted - curMp} MP!");
  100. myDic[currHero][1] = lifted;
  101. }
  102.  
  103.  
  104. }
  105. else if (singleComand == "Heal") //Heal – {hero name} – {amount}
  106.  
  107. {
  108. int amount = int.Parse(currCommands[2]);
  109. int curHp = myDic[currHero][0];
  110. int lifted = curHp + amount;
  111.  
  112. if (lifted > 100)
  113. {
  114.  
  115. lifted = 100;
  116. Console.WriteLine($"{currHero} healed for {100 - curHp} HP!");
  117.  
  118. myDic[currHero][0] = 100;
  119. }
  120. else
  121. {
  122.  
  123. Console.WriteLine($"{currHero} healed for {lifted - curHp} HP!");
  124. myDic[currHero][0] = lifted;
  125. }
  126.  
  127. }
  128. }
  129.  
  130. foreach (var kvp in myDic.OrderByDescending(x => x.Value[0]).ThenBy(y => y.Key))
  131. {
  132. Console.WriteLine(kvp.Key);
  133. Console.WriteLine($" HP: {kvp.Value[0]}");
  134. Console.WriteLine($" MP: {kvp.Value[1]}");
  135. }
  136. }
  137. }
  138. }
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement