public static Hero CreateHero(string name, string heroType)
        {
            Hero hero;

            if (heroType == "Druid")
            {
                hero = new Druid(name);
            }
            else if (heroType == "Paladin")
            {
                hero = new Paladin(name);
            }
            else if (heroType == "Rogue")
            {
                hero = new Rogue(name);
            }
            else if (heroType == "Warrior")
            {
                hero = new Warrior(name);
            }
            else
            {
                throw new ArgumentException("Invalid hero!");
            }

            return(hero);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            int heroesNeeded = int.Parse(Console.ReadLine());

            List <BaseHero> heroes = new List <BaseHero>();

            while (heroes.Count < heroesNeeded)
            {
                string heroName = Console.ReadLine();
                string heroType = Console.ReadLine();

                switch (heroType)
                {
                case "Paladin":
                    Paladin paladin = new Paladin(heroName);
                    heroes.Add(paladin);
                    break;

                case "Druid":
                    Druid druid = new Druid(heroName);
                    heroes.Add(druid);
                    break;

                case "Warrior":
                    Warrior warrior = new Warrior(heroName);
                    heroes.Add(warrior);
                    break;

                case "Rogue":
                    Rogue rogue = new Rogue(heroName);
                    heroes.Add(rogue);
                    break;

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

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

            int squadPower = 0;

            foreach (BaseHero hero in heroes)
            {
                squadPower += hero.Power;
                Console.WriteLine(hero.CastAbility());
            }

            if (squadPower >= bossHealth)
            {
                Console.WriteLine("Victory!");
            }
            else
            {
                Console.WriteLine("Defeat...");
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            int             n         = int.Parse(Console.ReadLine());
            List <BaseHero> raidGroup = new List <BaseHero>();

            while (raidGroup.Count != n)
            {
                string name = Console.ReadLine();
                string type = Console.ReadLine();
                //var classType = Type.GetType(type);
                //var hero = Activator.CreateInstance(classType);

                switch (type)
                {
                case "Paladin":
                    BaseHero hero = new Paladin(name);
                    raidGroup.Add(hero); break;

                case "Druid":
                    hero = new Druid(name);
                    raidGroup.Add(hero); break;

                case "Rogue":
                    hero = new Rogue(name);
                    raidGroup.Add(hero); break;

                case "Warrior":
                    hero = new Warrior(name);
                    raidGroup.Add(hero); break;

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


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

            foreach (var hero in raidGroup)
            {
                Console.WriteLine(hero.CastAbility());
                heroPower += hero.Power;
            }
            if (heroPower >= bossPower)
            {
                Console.WriteLine("Victory!");
            }
            else
            {
                Console.WriteLine("Defeat...");
            }
        }