public IBaseHero ProduceHero(string type, string name)
        {
            IBaseHero hero = null;

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

            return(hero);
        }
Пример #2
0
        public IBaseHero CreateHero(string name, string type)
        {
            IBaseHero curHero = null;

            switch (type)
            {
            case "Druid":
                curHero = new Druid(name);
                break;

            case "Paladin":
                curHero = new Paladin(name);
                break;

            case "Rogue":
                curHero = new Rogue(name);
                break;

            case "Warrior":
                curHero = new Warrior(name);
                break;

            default:
                throw new ArgumentException("Invalid hero!");
            }
            return(curHero);
        }
Пример #3
0
        public void Run()
        {
            int neededValidHeros = int.Parse(Console.ReadLine());
            int currValidHeros   = 0;

            while (currValidHeros != neededValidHeros)
            {
                string name = Console.ReadLine();
                string type = Console.ReadLine();
                try
                {
                    IBaseHero hero = this.heroFactory.ProduceHero(type, name);
                    if (hero == null)
                    {
                        throw new InvalidOperationException("Invalid hero!");
                    }
                    this.heros.Add(hero);
                    currValidHeros++;
                }
                catch (InvalidOperationException ioe)
                {
                    Console.WriteLine(ioe.Message);
                }
            }
            int bossPower = int.Parse(Console.ReadLine());

            foreach (var hero in this.heros)
            {
                Console.WriteLine(hero.CastAbility());
            }
            int herosTotalPower = this.heros.Sum(x => x.Power);

            if (herosTotalPower >= bossPower)
            {
                Console.WriteLine("Victory!");
            }
            else
            {
                Console.WriteLine("Defeat...");
            }
        }
Пример #4
0
        public IBaseHero ProduceHero(string type, string name)
        {
            IBaseHero hero = null;

            if (type == "Druid")
            {
                hero = new Druid(name);
            }
            else if (type == "Paladin")
            {
                hero = new Paladin(name);
            }
            else if (type == "Rogue")
            {
                hero = new Rogue(name);
            }
            else if (type == "Warrior")
            {
                hero = new Warrior(name);
            }
            return(hero);
        }
        public void Run()
        {
            var counter = 0;
            var n       = int.Parse(Console.ReadLine()); // number of commands

            while (counter != n)
            {
                var name = Console.ReadLine();
                var type = Console.ReadLine();
                try
                {
                    IBaseHero hero = this.factory.ProduceHero(type, name);
                    heroes.Add(hero);
                    counter++;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            var bossPower  = int.Parse(Console.ReadLine());
            var heroesPowr = heroes.Sum(x => x.Power);

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

            if (heroesPowr >= bossPower)
            {
                Console.WriteLine("Victory!");
            }
            else
            {
                Console.WriteLine("Defeat...");
            }
        }
Пример #6
0
        public void Run()
        {
            int n = int.Parse(this.reader.ReadLine());


            while (heroes.Count < n)
            {
                string name = this.reader.ReadLine();
                string type = this.reader.ReadLine();

                try
                {
                    IBaseHero curHero = heroCreator.CreateHero(name, type);
                    this.heroes.Add(curHero);
                }
                catch (ArgumentException e)
                {
                    this.writer.WriteLine(e.Message);
                }
            }

            int bossPower = int.Parse(this.reader.ReadLine());

            foreach (IBaseHero hero in heroes)
            {
                this.totalHeroPower += hero.Power;
                this.writer.WriteLine(hero.CastAbility());
            }

            if (bossPower > this.totalHeroPower)
            {
                this.writer.WriteLine("Defeat...");
            }
            else
            {
                this.writer.WriteLine("Victory!");
            }
        }
Пример #7
0
        public void Run()
        {
            var n = int.Parse(reader.ReadLine());

            while (this.heroes.Count != n)
            {
                string heroName = reader.ReadLine();
                string heroType = reader.ReadLine();

                try
                {
                    IBaseHero hero = this.heroFactory.ProduceHero(heroName, heroType);
                    this.heroes.Add(hero);
                }
                catch (InvalidHeroException ihe)
                {
                    writer.WriteLine(ihe.Message);
                }
            }

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

            foreach (IBaseHero hero in this.heroes)
            {
                writer.WriteLine(hero.CastAbility());
            }
            var totalHeroesPower = this.heroes.Sum(h => h.Power);

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