TheBulgarianWolf

Nether Realm

Apr 18th, 2021
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Nether_Realms
  7. {
  8.     public class Demon
  9.     {
  10.         public string Name { get; set; }
  11.         public int Health { get; set; }
  12.         public double Damage { get; set; }
  13.  
  14.     }
  15.  
  16.     class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             Regex hpRegex = new Regex(@"[^\d\-+.*\/]");
  21.             Regex numRegex = new Regex(@"[+\-]{0,1}\d+\.?\d*");
  22.             Regex amplifiersRegex = new Regex(@"[*\/]");
  23.             string[] demons = Console.ReadLine().Split(new[] { ',',' ' }, StringSplitOptions.RemoveEmptyEntries);
  24.             List<Demon> demonsList = new List<Demon>();
  25.             foreach(string demon in demons)
  26.             {
  27.                 MatchCollection hpMatches = hpRegex.Matches(demon);
  28.                 int health = GetHealth(hpMatches);
  29.  
  30.                 MatchCollection numbersMatches = numRegex.Matches(demon);
  31.                 double damage = GetBaseDamage(numbersMatches);
  32.  
  33.                 MatchCollection ampMatches = amplifiersRegex.Matches(demon);
  34.                 foreach (Match match in ampMatches)
  35.                 {
  36.                     if(match.Value == "*")
  37.                     {
  38.                         damage *= 2;
  39.                     }
  40.                     else
  41.                     {
  42.                         damage /= 2;
  43.                     }
  44.                 }
  45.  
  46.                 demonsList.Add(new Demon
  47.                 {
  48.                     Name = demon,
  49.                     Health = health,
  50.                     Damage = damage
  51.                 });
  52.                
  53.             }
  54.  
  55.             List<Demon> sorted = demonsList.OrderBy(d => d.Name).ToList();
  56.  
  57.             foreach(Demon demon in sorted)
  58.             {
  59.                 Console.WriteLine(demon.Name + "  -  " + demon.Health + " health, " + demon.Damage + " damage.");
  60.             }
  61.         }
  62.  
  63.         private static double GetBaseDamage(MatchCollection matchCollection)
  64.         {
  65.             double damage = 0;
  66.             foreach (Match match in matchCollection)
  67.             {
  68.                 damage += double.Parse(match.Value);
  69.             }
  70.  
  71.             return damage;
  72.         }
  73.  
  74.         private static int GetHealth(MatchCollection matchCollection)
  75.         {
  76.             int sum = 0;
  77.             foreach(Match match in matchCollection)
  78.             {
  79.                 sum += char.Parse(match.Value);
  80.             }
  81.  
  82.             return sum;
  83.         }
  84.     }
  85. }
  86.  
Add Comment
Please, Sign In to add comment