Advertisement
knoteva

03. Battle Manager

Aug 5th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03._Program
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var healthD = new Dictionary<string, int>();
  12.             var energyD = new Dictionary<string, int>();
  13.  
  14.             var dict = new Dictionary<string, List<int>>();
  15.             var line = string.Empty;
  16.  
  17.             while ((line = Console.ReadLine()) != "Results")
  18.             {
  19.                 string command = line.Split(":")[0];
  20.  
  21.                 if (command == "Add")
  22.                 {
  23.                     string personName = line.Split(":")[1];
  24.                     int health = int.Parse(line.Split(":")[2]);
  25.                     int energy = int.Parse(line.Split(":")[3]);
  26.  
  27.                     if (!dict.ContainsKey(personName))
  28.                     {
  29.                         dict.Add(personName, new List<int>());
  30.                         dict[personName].Add(0);
  31.                         dict[personName].Add(energy);
  32.                     }
  33.                     dict[personName][0] += health;
  34.                 }
  35.                 else if (command == "Attack")
  36.                 {
  37.                     string attackerName = line.Split(":")[1];
  38.                     string defenderName = line.Split(":")[2];
  39.                     int damage = int.Parse(line.Split(":")[3]);
  40.  
  41.                     if (dict.ContainsKey(attackerName) && dict.ContainsKey(defenderName))
  42.                     {
  43.                         dict[defenderName][0] -= damage;
  44.                         dict[attackerName][1] -= 1;
  45.                         if (dict[defenderName][0] <= 0)
  46.                         {
  47.                             Console.WriteLine($"{defenderName} was disqualified!");
  48.                             dict.Remove(defenderName);
  49.                            
  50.                         }
  51.  
  52.                         if (dict[attackerName][1] <= 0)
  53.                         {
  54.                             Console.WriteLine($"{attackerName} was disqualified!");
  55.                             dict.Remove(attackerName);
  56.                            
  57.                         }
  58.                     }
  59.                 }
  60.                 else if (command == "Delete")
  61.                 {
  62.                     string username = line.Split(":")[1];
  63.                     if (username == "All")
  64.                     {
  65.                         dict.Clear();
  66.                        
  67.                     }
  68.                     else if(dict.ContainsKey(username))
  69.                     {
  70.                         dict.Remove(username);
  71.                     }
  72.                 }
  73.             }
  74.  
  75.             Console.WriteLine($"People count: {dict.Keys.Count}");
  76.  
  77.             foreach (var item in dict.OrderByDescending(x => x.Value[0]).ThenBy(x => x.Key))
  78.             {
  79.                 Console.WriteLine($"{item.Key} - {item.Value[0]} - {item.Value[1]}");
  80.             }
  81.  
  82.            
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement