Advertisement
silvana1303

battle manager

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