Advertisement
silvana1303

heroes of code and logic

Jul 27th, 2020 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.57 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text.RegularExpressions;
  5. using System.Runtime.InteropServices;
  6. using System.Data;
  7.  
  8. namespace _02._Boss_Rush
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var times = int.Parse(Console.ReadLine());
  15.  
  16.             Dictionary<string, int> health = new Dictionary<string, int>();
  17.             Dictionary<string, int> mana = new Dictionary<string, int>();
  18.  
  19.             for (int i = 0; i < times; i++)
  20.             {
  21.                 string[] input = Console.ReadLine().Split();
  22.  
  23.                 //{hero name} {HP} {MP}
  24.  
  25.                 if (!health.ContainsKey(input[0]))
  26.                 {
  27.                     health[input[0]] = int.Parse(input[1]);
  28.                     mana[input[0]] = int.Parse(input[2]);
  29.                 }
  30.             }
  31.  
  32.             string[] command = Console.ReadLine().Split(" - ");
  33.  
  34.             while (command[0] != "End")
  35.             {
  36.                 if (command[0] == "CastSpell")
  37.                 {
  38.                     //CastSpell – {hero name} – {MP needed} – {spell name}
  39.                     int need = int.Parse(command[2]);
  40.                     if (need > mana[command[1]])
  41.                     {
  42.                         Console.WriteLine($"{command[1]} does not have enough MP to cast {command[3]}!");
  43.                     }
  44.                     else
  45.                     {
  46.                         mana[command[1]] -= need;
  47.                         int left = mana[command[1]];
  48.                         Console.WriteLine($"{command[1]} has successfully cast {command[3]} and now has {left} MP!");
  49.                     }
  50.                 }
  51.                 if (command[0] == "TakeDamage")
  52.                 {
  53.                     //TakeDamage – {hero name} – {damage} – {attacker}
  54.                     health[command[1]] -= int.Parse(command[2]);
  55.  
  56.                     if (health[command[1]] <= 0)
  57.                     {
  58.                         health.Remove(command[1]);
  59.                         mana.Remove(command[1]);
  60.                         Console.WriteLine($"{command[1]} has been killed by {command[3]}!");
  61.                     }
  62.                     else
  63.                     {
  64.                         int current = health[command[1]];
  65.                         Console.WriteLine($"{command[1]} was hit for {int.Parse(command[2])} HP by {command[3]} and now has {current} HP left!");
  66.                     }
  67.                 }
  68.                 if (command[0] == "Recharge")
  69.                 {
  70.                     //Recharge – {hero name} – {amount}
  71.  
  72.                     mana[command[1]] += int.Parse(command[2]);
  73.  
  74.                     if (mana[command[1]] > 200)
  75.                     {
  76.                         int difference = mana[command[1]] - 200;
  77.                         int amount = int.Parse(command[2]) - difference;
  78.                         mana[command[1]] = 200;
  79.                         Console.WriteLine($"{command[1]} recharged for {amount} MP!");
  80.                     }
  81.                     else
  82.                     {
  83.                         Console.WriteLine($"{command[1]} recharged for {int.Parse(command[2])} MP!");
  84.                     }
  85.  
  86.                 }
  87.                 if (command[0] == "Heal")
  88.                 {
  89.                     //Heal – {hero name} – {amount}
  90.  
  91.                     health[command[1]] += int.Parse(command[2]);
  92.  
  93.                     if (health[command[1]] > 100)
  94.                     {
  95.                         int difference = health[command[1]] - 100;
  96.                         int amount = int.Parse(command[2]) - difference;
  97.                         health[command[1]] = 100;
  98.                         Console.WriteLine($"{command[1]} healed for {amount} HP!");
  99.                     }
  100.                     else
  101.                     {
  102.                         Console.WriteLine($"{command[1]} healed for {int.Parse(command[2])} HP!");
  103.                     }
  104.                 }
  105.  
  106.                 command = Console.ReadLine().Split(" - ");
  107.             }
  108.  
  109.             //•   Print all members of your party who are still alive, sorted by their HP in descending order,
  110.             //then by their name in ascending order, in the following format (their HP/MP need to be indented 2 spaces):
  111.  
  112.             foreach (var item in health.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  113.             {
  114.                 Console.WriteLine(item.Key);
  115.                 Console.WriteLine($"  HP: {item.Value}");
  116.                 Console.WriteLine($"  MP: {mana[item.Key]}");
  117.             }
  118.         }
  119.     }
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement