Esempio n. 1
0
        public void CantReturnHeroWithBadId()
        {
            //Arrange
            Hero hero = new Hero(1, "Slaughter", 10, 15, "Warrior", 1);
            var mock = new Mock<IService<Hero>>(); // tworzenie symulacji serwisu
            mock.Setup(s => s.GetObjectById(1)).Returns(hero);

            var manager = new HeroManager(new MenuActionService(), mock.Object);

            //Act
            var returnedHero = manager.GetHeroById(2);

            //Assert
            returnedHero.Should().BeNull();
            returnedHero.Should().NotBeSameAs(hero);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            MenuActionService menuActionService = new MenuActionService();
            HeroService       heroService       = new HeroService();
            HeroManager       heroManager       = new HeroManager(menuActionService, heroService);
            EnemyService      enemyService      = new EnemyService();
            StoryManager      storyManager;
            int         tryHard       = 0;
            bool        choseLvlOne   = false;
            bool        choseLvlTwo   = false;
            bool        choseLvlThree = false;
            int         lastDiffLvl   = 0;
            List <Hero> heroes        = null;

            Console.WriteLine("Welcome to RPG Game app!");
            while (true)
            {
                int exit = 0;
                Console.WriteLine("Please let me know what you want to do:");
                var mainMenu = menuActionService.GetMenuActionsByMenuName("Main");
                for (int i = 0; i < mainMenu.Count; i++)
                {
                    Console.WriteLine($"{mainMenu[i].Id}. {mainMenu[i].Name}");
                }

                var operation = Console.ReadKey();

                switch (operation.KeyChar)
                {
                case '1':
                    var newId = heroManager.AddNewHero();
                    break;

                case '2':
                    heroManager.RemoveHero();
                    break;

                case '3':
                    heroManager.HeroDetails();
                    break;

                case '4':
                    var toShow = heroManager.ShowHeroes();
                    Console.WriteLine(toShow.ToStringTable(new[] { "Id", "Name", "Health", "Max Health",
                                                                   "Attack", "Heal Level", "Experience", "Level", "Required Experience",
                                                                   "Profession", "Typ Id" }, a => a.Id, a => a.Name, a => a.Health, a => a.MaxHealth,
                                                           a => a.Attack, a => a.HealLvl, a => a.Exp, a => a.Level, a => a.RequiredExp,
                                                           a => a.Profession, a => a.TypeId));
                    break;

                case '5':
                    heroes = heroManager.GetAllHeroes();
                    if (heroes.Count > 0)
                    {
                        Console.WriteLine();
                        Console.WriteLine(heroes.ToStringTable(new[] { "Id", "Name", "Health", "Max Health",
                                                                       "Attack", "Heal Level", "Experience", "Level", "Required Experience",
                                                                       "Profession", "Typ Id" }, a => a.Id, a => a.Name, a => a.Health, a => a.MaxHealth,
                                                               a => a.Attack, a => a.HealLvl, a => a.Exp, a => a.Level, a => a.RequiredExp,
                                                               a => a.Profession, a => a.TypeId));
                        int chosenHero = -1;

                        Hero hero = null;
                        while (hero == null)
                        {
                            chosenHero = heroManager.SelectCharacter();

                            if (chosenHero == -1)
                            {
                                break;
                            }

                            hero = heroManager.GetHeroById(chosenHero);
                        }

                        if (chosenHero != -1)
                        {
                            Console.WriteLine($"You chose Hero {hero.Name}, level:{hero.Level}, profession:{hero.Profession}");
                            storyManager = new StoryManager(menuActionService, hero, enemyService);
                            storyManager.SetLastDiffLvl(lastDiffLvl);
                            storyManager.Start();

                            if (storyManager.DiffLvl == lastDiffLvl)
                            {
                                tryHard++;
                                enemyService.UpgradeEnemiesByDiffLvl(tryHard, storyManager.DiffLvl);
                            }
                            else
                            {
                                tryHard = 0;
                            }

                            lastDiffLvl = storyManager.DiffLvl;
                            hero.Reset();

                            switch (storyManager.DiffLvl)
                            {
                            case 1:
                                choseLvlOne = true;
                                break;

                            case 2:
                                choseLvlTwo = true;
                                break;

                            case 3:
                                choseLvlThree = true;
                                break;
                            }

                            if (choseLvlOne && choseLvlTwo && choseLvlThree)
                            {
                                enemyService.UpgradeEnemies(1);
                                choseLvlOne   = false;
                                choseLvlTwo   = false;
                                choseLvlThree = false;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("\nThere is no heroes to choose");
                    }
                    break;

                case '6':
                    exit = 1;
                    if (heroes != null)
                    {
                        bool IsFileCreated = CreateXmlFileWithAllHeroes(heroes);
                        if (IsFileCreated)
                        {
                            Console.WriteLine("\nSaved all Heroes in file listOfAllHeroes.xml");
                        }
                    }
                    Console.WriteLine("Press Enter to continue");
                    Console.ReadLine();
                    break;

                default:
                    Console.WriteLine("Action you entered does not exist");
                    break;
                }

                if (exit == 1)
                {
                    break;
                }
            }
        }