LardaX

Nether-Realms

Oct 24th, 2016
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 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. using System.Threading.Tasks;
  7.  
  8. namespace Nether_Realms
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             char[] delimiters = new char[] { ' ', ',' };
  15.  
  16.             List<Demon> demons = new List<Demon>();
  17.  
  18.             string[] demonNames = Console.ReadLine().Split(delimiters, StringSplitOptions.RemoveEmptyEntries).ToArray();
  19.  
  20.             foreach (string demonInput in demonNames)
  21.             {
  22.                 string name = demonInput;
  23.                 string hpPattern = @"[^0-9\+\-\*/\.]";
  24.  
  25.                 Regex hpRegex = new Regex(hpPattern);
  26.                 MatchCollection hpCollection = hpRegex.Matches(name);
  27.  
  28.                 int health = 0;
  29.  
  30.                 foreach (Match match in hpCollection)
  31.                 {
  32.                     health += char.Parse(match.Groups[0].ToString());
  33.                 }
  34.  
  35.                 string dmgPattern = @"[\-|\+]?[0-9]+\.?[0-9]*";
  36.                 Regex dmgRegex = new Regex(dmgPattern);
  37.                 MatchCollection dmgCollection = dmgRegex.Matches(name);
  38.  
  39.                 double damage = 0;
  40.  
  41.                 foreach (Match match in dmgCollection)
  42.                 {
  43.                     damage += double.Parse(match.Groups[0].ToString());
  44.                 }
  45.  
  46.                 string multiplyPattern = @"[/|\*]";
  47.                 Regex multiplyRegex = new Regex(multiplyPattern);
  48.                 MatchCollection multiplyCollection = multiplyRegex.Matches(name);
  49.  
  50.                 foreach (Match match in multiplyCollection)
  51.                 {
  52.                     if (match.Groups[0].ToString().Equals("/"))
  53.                     {
  54.                         damage /= 2;
  55.                     }
  56.                     else if (match.Groups[0].ToString().Equals("*"))
  57.                     {
  58.                         damage *= 2;
  59.                     }
  60.                 }
  61.  
  62.                 Demon demon = new Demon(name, health, damage);
  63.  
  64.                 demons.Add(demon);
  65.  
  66.             }
  67.  
  68.             demons = demons.OrderBy(d => d.Name).ToList();
  69.  
  70.             foreach (Demon currentDemon in demons)
  71.             {
  72.                 Console.WriteLine($"{currentDemon.Name} - {currentDemon.Health} health, {currentDemon.Damage:f2} damage ");
  73.             }
  74.  
  75.         }
  76.     }
  77.  
  78.     class Demon
  79.     {
  80.         public string Name;
  81.         public int Health;
  82.         public double Damage;
  83.  
  84.         public Demon(string name, int health, double damage)
  85.         {
  86.             this.Name = name;
  87.             this.Health = health;
  88.             this.Damage = damage;
  89.         }
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment