예제 #1
0
        static void GetDemonDamage(string demonName, Demon demon)
        {
            var damagePattern = @"(\+|-)?\d+(?:\.?\d+)?";

            var damage    = Regex.Matches(demonName, damagePattern);
            var damageSum = 0m;

            foreach (Match match in damage)
            {
                damageSum += decimal.Parse(match.Value);
            }
            var modifiers = demonName
                            .Where(a => a == '*' || a == '/')
                            .ToArray();

            foreach (var sign in modifiers)
            {
                switch (sign)
                {
                case '*':
                    damageSum *= 2;
                    break;

                case '/':
                    damageSum /= 2;
                    break;
                }
            }
            demon.Damage = damageSum;
        }
예제 #2
0
        public static Demon ParseDemon(string demonName)
        {
            var demon = new Demon();

            demon.Name = demonName;

            GetDemonHealth(demonName, demon);
            GetDemonDamage(demonName, demon);

            return(demon);
        }
예제 #3
0
        static void GetDemonHealth(string demonName, Demon demon)
        {
            var listDemons = new List <int>();

            var healthPattern = @"[^0-9+\-*\/\.]";

            var health = Regex.Matches(demonName, healthPattern)
                         .Cast <Match>()
                         .Select(a => char.Parse(a.Value))
                         .ToArray();

            foreach (var element in health)
            {
                listDemons.Add(element);
            }

            var demonHealth = listDemons.Sum();

            demon.Health = demonHealth;
        }