private static BaseHero GetHero(string heroName, string heroType, HeroFactory factory)
        {
            switch (heroType.ToLower())
            {
            case "druid":
                factory = new DruidFactory(heroName);
                break;

            case "paladin":
                factory = new PaladinFactory(heroName);
                break;

            case "rogue":
                factory = new RogueFactory(heroName);
                break;

            case "warrior":
                factory = new WarriorFactory(heroName);
                break;

            default:
                throw new InvalidOperationException("Invalid hero!");
            }

            return(factory.CreateHero());
        }
示例#2
0
        public void Run()
        {
            List <BaseHero> raidGroup = new List <BaseHero>();
            HeroFactory     factory   = null;

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

            while (raidGroup.Count < n)
            {
                string name      = Console.ReadLine();
                string type      = Console.ReadLine();
                bool   validHero = true;
                switch (type)
                {
                case "Paladin":
                    factory = new PaladinFactory(name, 100);
                    break;

                case "Druid":
                    factory = new DruidFactory(name, 80);
                    break;

                case "Warrior":
                    factory = new WarriorFactory(name, 100);
                    break;

                case "Rogue":
                    factory = new RogueFactory(name, 80);
                    break;

                default:
                    Console.WriteLine("Invalid hero!");
                    validHero = false;
                    break;
                }
                if (validHero)
                {
                    raidGroup.Add(factory.GetHero());
                }
            }
            int sumPower = 0;

            foreach (var hero in raidGroup)
            {
                Console.WriteLine(hero.CastAbility());
                sumPower += hero.Power;
            }
            int boss = int.Parse(Console.ReadLine());

            if (boss > sumPower)
            {
                Console.WriteLine("Defeat...");
            }
            else
            {
                Console.WriteLine("Victory!");
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            var heroes = new List <BaseHero>();
            var n      = int.Parse(Console.ReadLine());

            for (var i = 0; i < n; i++)
            {
                var name = Console.ReadLine();
                var type = Console.ReadLine();

                HeroFactory factory = null;
                switch (type)
                {
                case "Druid":
                    factory = new DruidFactory(name);
                    break;

                case "Paladin":
                    factory = new PaladinFactory(name);
                    break;

                case "Rogue":
                    factory = new RogueFactory(name);
                    break;

                case "Warrior":
                    factory = new WarriorFactory(name);
                    break;

                default:
                    Console.WriteLine("Invalid hero!");
                    i--;
                    continue;
                }

                var hero = factory.MakeHero();
                heroes.Add(hero);
            }

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

            foreach (var hero in heroes)
            {
                Console.WriteLine(hero.CastAbility());
            }
            var totalPower = heroes.Sum(hero => hero.Power);

            Console.WriteLine(totalPower >= bossPower ? "Victory!" : "Defeat...");
        }
示例#4
0
        static void Main()
        {
            List <HeroFactory> heroes    = new List <HeroFactory>();
            List <BaseHero>    raidGroup = new List <BaseHero>();
            int rotation = int.Parse(Console.ReadLine());

            for (int i = 0; i < rotation; i++)
            {
                string heroName  = Console.ReadLine();
                string heroClass = Console.ReadLine();

                switch (heroClass.ToLower())
                {
                case "druid":
                    HeroFactory druid = new DruidFactory(heroName);
                    heroes.Add(druid);
                    break;

                case "paladin":
                    HeroFactory paladin = new PaladinFactory(heroName);
                    heroes.Add(paladin);
                    break;

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

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

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

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

            foreach (var hero in heroes)
            {
                raidGroup.Add(hero.GetHero());
            }

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

            foreach (var hero in raidGroup)
            {
                totalHeroPower += hero.Power;
            }

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