static void Main(string[] args) { string[] deamonNames = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); List <Deamon> deamons = new List <Deamon>(); foreach (var deamon in deamonNames) { // get health int health = 0; string healthCharsPattern = @"[^+\-*\/\.0-9]"; Regex healthRegex = new Regex(healthCharsPattern); MatchCollection matchHealth = healthRegex.Matches(deamon); foreach (Match m in matchHealth) { health += char.Parse(m.Value); } // get damage double damage = 0.0; string damagePattern = @"\-?\d+\.?\d*"; Regex damageRegex = new Regex(damagePattern); MatchCollection matchDamage = damageRegex.Matches(deamon); foreach (Match m in matchDamage) { damage += double.Parse(m.Value); } // multiply and divide foreach (var symbol in deamon) { if (symbol == '*') { damage *= 2; } else if (symbol == '/') { damage /= 2; } } Deamon newDeamon = new Deamon(); newDeamon.Name = deamon; newDeamon.Health = health; newDeamon.Damage = damage; deamons.Add(newDeamon); } foreach (var deamon in deamons.OrderBy(x => x.Name)) { Console.WriteLine($"{deamon.Name} - {deamon.Health} health, {deamon.Damage:f2} damage"); } }
static void Main(string[] args) { string[] demons = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); var deamons = new SortedDictionary <string, Deamon>(); foreach (var demon in demons) { int demonsHealth = GetDemonHealth(demon); double demonsDamage = GetDeamonDamage(demon); Deamon nextDeamon = new Deamon(demon, demonsHealth, demonsDamage); deamons.Add(demon, nextDeamon); } foreach (var item in deamons) { Console.WriteLine($"{item.Key} - {item.Value.Health} health, {item.Value.Damage:F2} damage"); }
public static void GetVillageScenario(Hero playerHero) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nIn the haunted village you are attacked by the deamon from the ancient world! \n" + "You have to defend yourself!"); Console.ResetColor(); Console.WriteLine(); Hero deamon = new Deamon() { Name = "Gorlab", CharacterClass = "Deamon", Health = 55, Armor = 4, AttackMax = 15, }; if (IsHeroAlive(playerHero, deamon)) { SoundEffect.GetSound(Resource.deamon_death); Console.WriteLine(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("In the haunted village you have defeated deamon from the ancient world.\n" + "Without their master, the rest of the monsters fled this area.\n" + "You were able to eradicate the evil from this place.\n"); Console.ResetColor(); Console.WriteLine(); Console.WriteLine("[Press any key to exit game]"); Console.ReadKey(); Environment.Exit(0); } else { GetDefeatedInfo(); } }
static void Main() { var input = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); var healthStorage = new SortedDictionary <string, int>(); var damageStorage = new SortedDictionary <string, double>(); var bookOfEvil = new SortedDictionary <string, Deamon>(); for (int i = 0; i < input.Length; i++) { var name = input[i]; var totalHealth = GetHealth(input, i); var totalDamage = GetDamage(input, i); Deamon deamon = new Deamon(); deamon.Health = totalHealth; deamon.Damage = totalDamage; if (!bookOfEvil.ContainsKey(input[i])) { bookOfEvil.Add(input[i], deamon); } else { bookOfEvil[name].Health += totalHealth; bookOfEvil[name].Damage += totalDamage; } } foreach (var dzver in bookOfEvil) { Console.WriteLine($"{dzver.Key} - {dzver.Value.Health} health, {dzver.Value.Damage:f2} damage"); } }