コード例 #1
0
        public Hero CreateHero(params string[] heroArgs)
        {
            Hero currentHero = null;
            var  heroType    = heroArgs[0];
            var  heroName    = heroArgs[1];

            if (heroType == nameof(Druid))
            {
                currentHero = new Druid(heroName);
            }
            else if (heroType == nameof(Paladin))
            {
                currentHero = new Paladin(heroName);
            }
            else if (heroType == nameof(Rogue))
            {
                currentHero = new Rogue(heroName);
            }
            else if (heroType == nameof(Warrior))
            {
                currentHero = new Warrior(heroName);
            }

            return(currentHero);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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...");
            }
        }