public void Team_AddingSameHeroTwice_ThrowsException()
        {
            var sut  = new Team(Side.Dire);
            var hero = Helpers.CreateHero("Hero");

            Assert.DoesNotThrow(() => sut.AddHero(hero));
            var exception = Assert.Throws <ApplicationException>(() => sut.AddHero(hero));

            Assert.AreEqual("This team already contains Hero", exception.Message);
        }
        public void Team_AddsHero_NoExceptionThrown()
        {
            var sut  = new Team(Side.Dire);
            var hero = Helpers.CreateHero("Hero1");

            Assert.DoesNotThrow(() => sut.AddHero(hero));
        }
        public void Team_Adds6Heroes_ExceptionThrown()
        {
            var  sut = new Team(Side.Dire);
            Hero hero;

            for (var i = 0; i < 5; i++)
            {
                hero = Helpers.CreateHero("Hero" + i);
                Assert.DoesNotThrow(() => sut.AddHero(hero));
            }

            hero = Helpers.CreateHero("6thHero");
            var exception = Assert.Throws <ApplicationException>(() => sut.AddHero(hero));

            Assert.AreEqual("Team can't contain more than 5 heroes", exception.Message);
        }
Пример #4
0
    public static Team RandomEnemyTeam()
    {
        Team team = new Team();

        for (int i = 0; i < 3; ++i)
        {
            team.AddHero(RandomHero(RandomName()));
        }
        return(team);
    }
Пример #5
0
        public static Team LoadPlayerTeam(string PlayerName, int[] place)
        {
            Team t = new Team(false);

            using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                conn.Open();

                for (int i = 0; i < place.Length; i++)
                {
                    OleDbCommand    command = new OleDbCommand("SELECT * FROM " + PlayerName + " WHERE place=" + place[i] + ";", conn);
                    OleDbDataReader r       = null;

                    while (true)
                    {
                        try
                        {
                            r = command.ExecuteReader();

                            r.Read();

                            Hero hero = Reader.GetHero((int)r[1]);
                            hero.stats.SetLevel((int)r["lvl"], (int)r["exp"]);

                            t.AddHero(hero);
                            break;
                        }
                        catch (OleDbException e)
                        {
                            Console.Write("This Name doesn't exist. Enter Correct Name ");
                            PlayerName = Console.ReadLine();
                            r.Close();
                        }
                        catch (NullReferenceException e)
                        {
                            Console.Write(e.StackTrace);
                        }
                    }
                }
            }

            return(t);
        }
Пример #6
0
        public static Team LoadMonsterTeam(int dungeonID)
        {
            Team t = new Team(true);

            using (OleDbConnection conn = new OleDbConnection(connectionString))
            {
                conn.Open();
                for (int i = 1; i <= 5; i++)
                {
                    OleDbCommand command = new OleDbCommand("SELECT * FROM Dungeon WHERE place=" + i, conn);

                    OleDbDataReader r = command.ExecuteReader();

                    r.Read();

                    Hero hero = Reader.GetHero((int)r["HeroId"]);
                    hero.stats.SetLevel(dungeonID, 0);

                    t.AddHero(hero);
                }
            }

            return(t);
        }
Пример #7
0
    public static void Main(String[] args)
    {
        MenuState state = MenuState.VILLAGE;

        while (true)
        {
            string selection = OutputMenu(state);
            try {
                if (state == MenuState.VILLAGE)
                {
                    if (selection == "1")
                    {
                        hero = RandomHero(RandomName());
                        output(hero.ToStr());
                        state = MenuState.RANDOM_HERO;
                    }
                    else if (selection == "2")
                    {
                        output(team.ToStr());
                    }
                    else if (selection == "3")
                    {
                        enemyTeam = RandomEnemyTeam();
                        output(enemyTeam.ToStr());
                    }
                    else if (selection == "4")
                    {
                        output("battle");
                        state = MenuState.BATTLE;
                    }
                    else if (selection == "5")
                    {
                        output("build sawmill");
                        if (village.HasBuilding(BuildingType.SAWMILL))
                        {
                            village.LevelupBuilding(BuildingType.SAWMILL);
                        }
                        else
                        {
                            village.AddBuilding(new Sawmill());
                        }
                    }
                    else if (selection == "0")
                    {
                        output("Bye bye.");
                        break;
                    }
                }
                else if (state == MenuState.RANDOM_HERO)
                {
                    if (selection == "1")
                    {
                        hero = RandomHero(RandomName());
                        output(hero.ToStr());
                    }
                    else if (selection == "2")
                    {
                        team.AddHero(hero);
                        state = MenuState.VILLAGE;
                    }
                    else if (selection == "3")
                    {
                        state = MenuState.VILLAGE;
                    }
                }
                else if (state == MenuState.BATTLE)
                {
                    if (team.IsAllDead())
                    {
                        output("you lose.");
                        state = MenuState.VILLAGE;
                    }
                    else if (enemyTeam.IsAllDead())
                    {
                        output("you win.");
                        state = MenuState.VILLAGE;
                    }
                    else if (selection == "1")
                    {
                        state = MenuState.BATTLE_ATTACK;
                    }
                }
                else if (state == MenuState.BATTLE_ATTACK)
                {
                    atker = team.GetHeroByIndex(int.Parse(selection) - 1);
                    state = MenuState.BATTLE_ATTACK_TARGET;
                }
                else if (state == MenuState.BATTLE_ATTACK_TARGET)
                {
                    defer = enemyTeam.GetHeroByIndex(int.Parse(selection) - 1);
                    List <string> result = Fight(atker, defer);
                    OutputList(result);

                    OutputBattleState(team, enemyTeam);
                    state = MenuState.BATTLE;
                }

                village.Tick();
            } catch {
                Console.WriteLine("error.");
            }
        }
    }