Beispiel #1
0
        // Расчет после завершения хода игроком
        internal void CalcFinalityTurn()
        {
            // Убеждаемся, что у нас не сломалось соответствие флагов
            foreach (PlayerLair pl in Lairs)
            {
                if (pl != null)
                {
                    if (pl.PriorityFlag != PriorityExecution.None)
                    {
                        Debug.Assert(ListFlags.IndexOf(pl) != -1);
                    }
                    else
                    {
                        Debug.Assert(ListFlags.IndexOf(pl) == -1);
                    }
                }
            }

            // Расчет флагов на логова
            List <PlayerLair> tempListLair = ListFlags.ToList();// Работаем с копией списка, так как текущий будет меняться по мере обработки флагов

            foreach (PlayerLair pl in tempListLair)
            {
                Battle             b;
                FormBattle         formBattle;
                FormProgressBattle formProgressBattle = null;

                if ((pl != null) && (pl.listAttackedHero.Count > 0))
                {
                    Debug.Assert((pl.TypeFlag == TypeFlag.Scout) || (pl.TypeFlag == TypeFlag.Attack) || (pl.TypeFlag == TypeFlag.Defense));

                    if (pl.TypeFlag == TypeFlag.Scout)
                    {
                        pl.DoScout();
                    }
                    else if (pl.TypeFlag == TypeFlag.Attack)
                    {
                        Debug.Assert(pl.Monsters.Count > 0);

                        PreparingForBattle();

                        // Включить, когда ИИ может выбирать цель
                        pl.PreparingForBattle();

                        //Debug.Assert(p.TargetLair.CombatHeroes.Count > 0);

                        bool showForPlayer = TypePlayer == TypePlayer.Human;
                        b = new Battle(this, pl, Lobby.Turn, FormMain.Rnd, showForPlayer);

                        if (showForPlayer)
                        {
                            formBattle = new FormBattle();
                            formBattle.ShowBattle(b);
                            formBattle.Dispose();
                        }
                        else
                        {
                            if (formProgressBattle == null)
                            {
                                formProgressBattle = new FormProgressBattle();
                            }

                            formProgressBattle.SetBattle(b, 1, 1);
                        }

                        if (b.Winner == this)
                        {
                            // Победил игрок
                            pl.DoCapture();
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        pl.DoDefense();
                    }
                }
            }
        }
        private void CalcBattles()
        {
            Battle             b;
            FormBattle         formBattle;
            FormProgressBattle formProgressBattle = null;

            foreach (Player p in Players)
            {
                p.BattleCalced = false;
            }

            // Бои с монстрами
            foreach (Player p in Players)
            {
                if (p.IsLive)
                {
                    p.PreparingForBattle();

                    // Включить, когда ИИ может выбирать цель
                    //Debug.Assert(p.TargetLair != null);
                    foreach (PlayerLair pl in p.ListFlags)
                    {
                        pl.PreparingForBattle();

                        //Debug.Assert(p.TargetLair.CombatHeroes.Count > 0);

                        bool showForPlayer = p.TypePlayer == TypePlayer.Human;
                        b = new Battle(p, pl, Turn, FormMain.Rnd, showForPlayer);

                        if (showForPlayer)
                        {
                            formBattle = new FormBattle();
                            formBattle.ShowBattle(b);
                            formBattle.Dispose();
                        }
                        else
                        {
                            if (formProgressBattle == null)
                            {
                                formProgressBattle = new FormProgressBattle();
                            }

                            formProgressBattle.SetBattle(b, Players.Count(), p.PlayerIndex + 1);
                        }

                        Battles.Add(b);
                    }
                }
            }

            return;

            int livePlayers = 0;

            foreach (Player p in Players)
            {
                if (p.IsLive)
                {
                    livePlayers++;
                }
            }
            Debug.Assert(livePlayers % 2 == 0);
            int pairs      = (livePlayers / 2) - 1;
            int numberPair = 0;

            foreach (Player p in Players)
            {
                p.BattleCalced = false;
            }

            foreach (Player p in Players)
            {
                if (p.IsLive == true)
                {
                    if (p.BattleCalced == false)
                    {
                        bool showForPlayer = (p.TypePlayer == TypePlayer.Human) || (p.Opponent.TypePlayer == TypePlayer.Human);
                        b = new Battle(p, p.Opponent, Turn, FormMain.Rnd, showForPlayer);

                        if (showForPlayer)
                        {
                            formBattle = new FormBattle();
                            formBattle.ShowBattle(b);
                            formBattle.Dispose();
                        }
                        else
                        {
                            numberPair++;
                            if (formProgressBattle == null)
                            {
                                formProgressBattle = new FormProgressBattle();
                            }

                            formProgressBattle.SetBattle(b, pairs, numberPair);
                        }

                        Battles.Add(b);
                    }
                }
            }

            if (formProgressBattle != null)
            {
                formProgressBattle.Dispose();
            }
        }