Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            int             lines   = int.Parse(Console.ReadLine());
            HeroCreator     creator = null;
            List <BaseHero> group   = new List <BaseHero>();
            BaseHero        hero    = null;


            for (int i = 0; i < lines; i++)
            {
                string name = Console.ReadLine();
                string type = Console.ReadLine();

                switch (type.ToLower())
                {
                case "druid":
                    creator = new DruidCreator(name);
                    hero    = creator.CreateHero();
                    group.Add(hero);
                    Console.WriteLine(hero.CastAbility());
                    break;

                case "paladin":
                    creator = new PaladinCreator(name);
                    hero    = creator.CreateHero();
                    group.Add(hero);
                    Console.WriteLine(hero.CastAbility());
                    break;

                case "rogue":
                    creator = new RogueCreator(name);
                    hero    = creator.CreateHero();
                    group.Add(hero);
                    Console.WriteLine(hero.CastAbility());
                    break;

                case "warrior":
                    creator = new WarriorCreator(name);
                    hero    = creator.CreateHero();
                    group.Add(hero);
                    Console.WriteLine(hero.CastAbility());
                    break;

                default:
                    Console.WriteLine("Invalid hero!");
                    lines++;
                    break;
                }
            }

            int bossPower  = int.Parse(Console.ReadLine());
            int groupPower = 0;

            if (group.Count > 0)
            {
                foreach (var unit in group)
                {
                    groupPower += unit.Power;
                }
            }

            if (bossPower <= groupPower)
            {
                Console.WriteLine("Victory!");
            }

            else
            {
                Console.WriteLine("Defeat...");
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            List <BaseHero> heroes      = new List <BaseHero>();
            BaseHeroCreator heroCreator = null;

            int number = int.Parse(Console.ReadLine());

            for (int i = 0; i < number; i++)
            {
                string name = Console.ReadLine();
                string type = Console.ReadLine();
                try
                {
                    switch (type)
                    {
                    case "Druid":
                        heroCreator = new DruidCreator(name);
                        break;

                    case "Paladin":
                        heroCreator = new PaladinCreator(name);
                        break;

                    case "Rogue":
                        heroCreator = new RogueCreator(name);
                        break;

                    case "Warrior":
                        heroCreator = new WarriorCreator(name);
                        break;

                    default:
                        i--;
                        throw new ArgumentException("Invalid hero!");
                    }

                    heroes.Add(heroCreator.GetBaseHero());
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            int bossPower = int.Parse(Console.ReadLine());

            int heroesPower = heroes.Sum(h => h.Power);

            foreach (var hero in heroes)
            {
                Console.WriteLine(hero.CastAbility());
            }

            if (bossPower > heroesPower)
            {
                Console.WriteLine("Defeat...");
            }
            else
            {
                Console.WriteLine("Victory!");
            }
        }