コード例 #1
0
ファイル: HeroManager.cs プロジェクト: vv-b-s/SoftUni
    public string AddHero(string heroName, string heroType)
    {
        var result = "";

        var hero = heroFactory.CreateHero(heroName, heroType);

        this.heroes[heroName] = hero;

        result = string.Format(Constants.HeroCreateMessage, heroType, heroName);

        return(result);
    }
コード例 #2
0
        public string AddHero(IList <string> arguments)
        {
            string heroName     = arguments[0];
            string heroTypeName = arguments[1];

            IHero hero = heroFactory.CreateHero(heroTypeName, heroName);

            this.heroes.Add(heroName, hero);

            string result = string.Format(Constants.HeroCreateMessage, hero.GetType().Name, hero.Name);

            return(result);
        }
コード例 #3
0
        public void Run()
        {
            int          n      = int.Parse(Console.ReadLine());
            List <IHero> heroes = new List <IHero>();

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

                IHero currHero = heroFactory.CreateHero(type, name);

                if (currHero != null)
                {
                    heroes.Add(currHero);
                }
                else
                {
                    Console.WriteLine("Invalid hero!");
                    i--;
                }
            }

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

            int result = 0;

            foreach (IHero hero in heroes)
            {
                Console.WriteLine(hero.ClassAbility());
                result += hero.Power;
            }

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