static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int counter = 0; List <BaseHero> heroes = new List <BaseHero>(); while (counter != n) { string name = Console.ReadLine(); string heroType = Console.ReadLine(); try { BaseHero hero = HeroFactory.Create(name, heroType); heroes.Add(hero); counter++; } catch (ArgumentException ae) { Console.WriteLine(ae.Message); } } int bossHelth = int.Parse(Console.ReadLine()); int damage = 0; foreach (var hero in heroes) { Console.WriteLine(hero.CastAbility()); damage += hero.Power; } if (damage >= bossHelth) { Console.WriteLine("Victory!"); } else { Console.WriteLine("Defeat..."); } }
static void Main(string[] args) { List <BaseHero> heroes = new List <BaseHero>(); int n = int.Parse(Console.ReadLine()); while (heroes.Count < n) { string name = Console.ReadLine(); string type = Console.ReadLine(); BaseHero hero = CreateHero(name, type); if (hero == null) { Console.WriteLine("Invalid hero!"); continue; } heroes.Add(hero); } int bossPower = int.Parse(Console.ReadLine()); foreach (BaseHero currentHero in heroes) { Console.WriteLine(currentHero.CastAbility()); bossPower -= currentHero.Power; } if (bossPower <= 0) { Console.WriteLine("Victory!"); } else { Console.WriteLine("Defeat..."); } }
static void Main(string[] args) { List <BaseHero> heros = new List <BaseHero>(); int n = int.Parse(Console.ReadLine()); while (heros.Count != n) { string name = Console.ReadLine(); string type = Console.ReadLine(); try { BaseHero hero = CreateHero(name, type); heros.Add(hero); } catch (Exception ex) { Console.WriteLine(ex.Message); } } int bossPower = int.Parse(Console.ReadLine()); int heroesPower = heros.Sum(p => p.Power); foreach (var hero in heros) { Console.WriteLine(hero.CastAbility()); } if (heroesPower >= bossPower) { Console.WriteLine("Victory!"); } else { Console.WriteLine("Defeat..."); } }
private static BaseHero CreateHero(string name, string type) { BaseHero hero = null; if (type == nameof(Druid)) { hero = new Druid(name); } else if (type == nameof(Paladin)) { hero = new Paladin(name); } else if (type == nameof(Rogue)) { hero = new Rogue(name); } else if (type == nameof(Warrior)) { hero = new Warrior(name); } return(hero); }
static void Main(string[] args) { List <BaseHero> raidGroup = new List <BaseHero>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string heroName = Console.ReadLine(); string heroType = Console.ReadLine(); BaseHero hero = null; try { if (heroType == "Druid") { hero = new Druid(heroName); } else if (heroType == "Paladin") { hero = new Paladin(heroName); } else if (heroType == "Warrior") { hero = new Warrior(heroName); } else if (heroType == "Rogue") { hero = new Rogue(heroName); } else { throw new InvalidHeroException(); } raidGroup.Add(hero); } catch (InvalidHeroException ex) { Console.WriteLine(ex.Message); i--; } } int result = raidGroup.Sum(h => h.Power); int bossPower = int.Parse(Console.ReadLine()); foreach (var hero in raidGroup) { Console.WriteLine(hero.CastAbility()); } if (result >= bossPower) { Console.WriteLine("Victory!"); } else { Console.WriteLine("Defeat..."); } }