Deserboy

Battle Manager

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