joro_thexfiles

Battle Manager

Aug 7th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Battle_Manager
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var health = new Dictionary<string, int>();
  12.             var energy = new Dictionary<string, int>();
  13.  
  14.             while (true)
  15.             {
  16.                 string text = Console.ReadLine();
  17.  
  18.                 if (text == "Results")
  19.                 {
  20.                     break;
  21.                 }
  22.                 else
  23.                 {
  24.                     string[] data = text.Split(":", StringSplitOptions.RemoveEmptyEntries);
  25.  
  26.                     string command = data[0];
  27.                     string name = data[1];
  28.  
  29.                     if (command == "Add")
  30.                     {
  31.                         int healthPoints = int.Parse(data[2]);
  32.                         int energyPoints = int.Parse(data[3]);
  33.  
  34.                         if (!health.ContainsKey(name))
  35.                         {
  36.                             health[name] = healthPoints;
  37.                             energy[name] = energyPoints;
  38.                         }
  39.                         else
  40.                         {
  41.                             health[name] += healthPoints;
  42.                         }
  43.                     }
  44.                     else if (command == "Attack")
  45.                     {
  46.                         string secondName = data[2];
  47.                         int damage = int.Parse(data[3]);
  48.  
  49.                         if (health.ContainsKey(name) & health.ContainsKey(secondName))
  50.                         {
  51.                             health[secondName] -= damage;
  52.  
  53.                             if (health[secondName] <= 0)
  54.                             {
  55.                                 health.Remove(secondName);
  56.                                 energy.Remove(secondName);
  57.  
  58.                                 Console.WriteLine($"{secondName} was disqualified!");
  59.                             }
  60.  
  61.                             energy[name]--;
  62.  
  63.                             if (energy[name] <= 0)
  64.                             {
  65.                                 health.Remove(name);
  66.                                 energy.Remove(name);
  67.  
  68.                                 Console.WriteLine($"{name} was disqualified!");
  69.                             }
  70.                         }
  71.                     }
  72.                     else if (command == "Delete")
  73.                     {
  74.                         if (name == "All")
  75.                         {
  76.                             health.Clear();
  77.                             energy.Clear();
  78.                         }
  79.                         else
  80.                         {
  81.                             if (health.ContainsKey(name))
  82.                             {
  83.                                 health.Remove(name);
  84.                             }
  85.  
  86.                             if (energy.ContainsKey(name))
  87.                             {
  88.                                 energy.Remove(name);
  89.                             }
  90.                         }
  91.                     }
  92.                 }
  93.             }
  94.  
  95.             Console.WriteLine($"People count: {health.Count}");
  96.  
  97.             foreach (var kvp in health
  98.                 .OrderByDescending(x=>x.Value)
  99.                 .ThenBy(x=>x.Key))
  100.             {
  101.                 Console.WriteLine($"{kvp.Key} - {kvp.Value} - {energy[kvp.Key]}");
  102.             }
  103.         }
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment