Advertisement
Guest User

Untitled

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