Beispiel #1
0
        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);

            if (m_robber == null)
            {
                return;
            }

            Graphics   g                 = pe.Graphics;
            Rectangle  rf1               = new Rectangle();
            RectangleF rf2               = new RectangleF();
            Pen        pen_Black         = new Pen(Color.Black);
            Pen        pen_BorderBetween = new Pen(Color.Blue);

            int ValidDealsCount     = m_robber.GetValidDealsCount();
            int CompletedDealsCount = m_robber.WhereCompleted() + 1;

            if (m_robber.WhereCompleted() != -1 && CompletedDealsCount < ValidDealsCount)
            {
                ValidDealsCount = CompletedDealsCount;
            }

            // V Разделитель
            int bonus_lines = 0, bonus_lines_ns = 0, bonus_lines_ew = 0;

            for (int i = 0; i < ValidDealsCount; i++)
            {
                if (m_robber.ScoreArray[i].NS_up != null && m_robber.ScoreArray[i].NS_up.Length != 0)
                {
                    bonus_lines_ns += m_robber.ScoreArray[i].NS_up.Length;
                }
                if (m_robber.ScoreArray[i].EW_up != null && m_robber.ScoreArray[i].EW_up.Length != 0)
                {
                    bonus_lines_ew += m_robber.ScoreArray[i].EW_up.Length;
                }
            }
            bonus_lines += (bonus_lines_ns > bonus_lines_ew ? bonus_lines_ns : bonus_lines_ew);

            int usual_lines = 0, usual_lines_ns = 0, usual_lines_ew = 0;
            int iNS = 0, iEW = 0;

            for (int i = 0; i < ValidDealsCount; i++)
            {
                if (m_robber.ScoreArray[i].EW_down != 0)
                {
                    usual_lines_ew++;
                    iEW += m_robber.ScoreArray[i].EW_down;
                }
                else if (m_robber.ScoreArray[i].NS_down != 0)
                {
                    usual_lines_ns++;
                    iNS += m_robber.ScoreArray[i].NS_down;
                }

                if (iNS >= 100 || iEW >= 100)
                {
                    usual_lines   += (usual_lines_ns > usual_lines_ew ? usual_lines_ns : usual_lines_ew);
                    usual_lines_ew = usual_lines_ns = 0;
                    iNS            = iEW = 0;
                }
            }
            usual_lines += (usual_lines_ns > usual_lines_ew ? usual_lines_ns : usual_lines_ew);

            int  total_lines               = bonus_lines + usual_lines;
            int  separators                = 1 + m_robber.HowManyValidGames();
            bool is_main_separator_half    = (usual_lines == 0 || bonus_lines == 0);
            bool is_closing_separator_half = (ValidDealsCount > 0 ? m_robber.IsClearAfterGame(ValidDealsCount - 1) : false);
            int  total_height              = total_lines * (int)size1.Height + separators * (1 + 2 * spaceV_Boundary);

            if (m_robber.IsCompleted())
            {
                total_height -= spaceV_Boundary;
            }

            if (total_lines > 0)
            {
                total_height += (total_lines - 1 - separators + (is_main_separator_half ? 1 : 0) + (is_closing_separator_half ? 1 : 0)) * space.Height;
            }

            // Посчитать, влезают ли все очки по вертикали:
            bool use_compact_bonuses     = false;                                                              // сжать бонусы?
            int  robber_line_full_height = offset.Height * 2 + (height_Header + spaceV_Header) + total_height; //полная высота

            if (robber_line_full_height > ClientSize.Height)
            {
                use_compact_bonuses = true;
            }
            if (bonus_lines == 0)
            {
                use_compact_bonuses = false;
            }

            // Сжать бонусы
            if (use_compact_bonuses)
            {
                bonus_lines  = 1;
                total_lines  = bonus_lines + usual_lines;
                total_height = total_lines * (int)size1.Height + separators * (1 + 2 * spaceV_Boundary);
                if (m_robber.IsCompleted())
                {
                    total_height -= spaceV_Boundary;
                }
                if (total_lines > 0)
                {
                    total_height += (total_lines - 1 - separators + (is_main_separator_half ? 1 : 0) + (is_closing_separator_half ? 1 : 0)) * space.Height;
                }
            }

            g.DrawLine(pen_Black, offset.Width + (int)size1.Width + 1 * space.Width, offset.Height + (height_Header + spaceV_Header), offset.Width + (int)size1.Width + 1 * space.Width, offset.Height + (height_Header + spaceV_Header) + total_height - 1); //добавить +1 за толстую черту


            // заголовок: NS и EW
            rf1.X      = offset.Width;
            rf1.Y      = offset.Height;
            rf1.Width  = (int)size1.Width;
            rf1.Height = height_Header;
            rf2        = SmallHelper.StringInMiddle(g, rf1, "NS", this.fontHeader);
            g.DrawString("NS", this.fontHeader, this.brushHeader, rf2);

            rf1.X = offset.Width + (int)size1.Width + 2 * space.Width + 1;
            rf2   = SmallHelper.StringInMiddle(g, rf1, "EW", this.fontHeader);
            g.DrawString("EW", this.fontHeader, this.brushHeader, rf2);



            // Бонусы
            if (!use_compact_bonuses)
            {
                bonus_lines_ns = 0;
                bonus_lines_ew = 0;
                rf1.Width      = (int)size1.Width;
                rf1.Height     = (int)size1.Height;
                for (int i = 0; i < ValidDealsCount; i++)
                {
                    if (m_robber.ScoreArray[i].NS_up != null && m_robber.ScoreArray[i].NS_up.Length != 0)
                    {
                        for (int j = 0; j < m_robber.ScoreArray[i].NS_up.Length; j++)
                        {
                            bonus_lines_ns++;
                            rf1.X = offset.Width;
                            rf1.Y = offset.Height + (height_Header + spaceV_Header) + (bonus_lines - bonus_lines_ns) * ((int)size1.Height + space.Height);
                            rf2   = SmallHelper.StringInMiddle(g, rf1, m_robber.ScoreArray[i].NS_up[j].ToString(), this.Font);
                            g.DrawString(m_robber.ScoreArray[i].NS_up[j].ToString(), this.Font, this.brushText, rf2);
                        }
                    }
                    if (m_robber.ScoreArray[i].EW_up != null && m_robber.ScoreArray[i].EW_up.Length != 0)
                    {
                        for (int j = 0; j < m_robber.ScoreArray[i].EW_up.Length; j++)
                        {
                            bonus_lines_ew++;
                            rf1.X = offset.Width + (int)size1.Width + 2 * space.Width + 1;
                            rf1.Y = offset.Height + (height_Header + spaceV_Header) + (bonus_lines - bonus_lines_ew) * ((int)size1.Height + space.Height);
                            rf2   = SmallHelper.StringInMiddle(g, rf1, m_robber.ScoreArray[i].EW_up[j].ToString(), this.Font);
                            g.DrawString(m_robber.ScoreArray[i].EW_up[j].ToString(), this.Font, this.brushText, rf2);
                        }
                    }
                }
            }
            else
            {
                int total_bonuses_NS = 0, total_bonuses_EW = 0;
                for (int i = 0; i < ValidDealsCount; i++)
                {
                    if (m_robber.ScoreArray[i].NS_up != null && m_robber.ScoreArray[i].NS_up.Length != 0)
                    {
                        for (int j = 0; j < m_robber.ScoreArray[i].NS_up.Length; j++)
                        {
                            total_bonuses_NS += m_robber.ScoreArray[i].NS_up[j];
                        }
                    }
                    if (m_robber.ScoreArray[i].EW_up != null && m_robber.ScoreArray[i].EW_up.Length != 0)
                    {
                        for (int j = 0; j < m_robber.ScoreArray[i].EW_up.Length; j++)
                        {
                            total_bonuses_EW += m_robber.ScoreArray[i].EW_up[j];
                        }
                    }
                }

                rf1.Width  = (int)size1.Width;
                rf1.Height = (int)size1.Height;
                rf1.X      = offset.Width;
                rf1.Y      = offset.Height + (height_Header + spaceV_Header);
                rf2        = SmallHelper.StringInMiddle(g, rf1, total_bonuses_NS.ToString(), this.Font);
                g.DrawString(total_bonuses_NS.ToString(), this.Font, this.brushText, rf2);
                rf1.X = offset.Width + (int)size1.Width + 2 * space.Width + 1;
                rf2   = SmallHelper.StringInMiddle(g, rf1, total_bonuses_EW.ToString(), this.Font);
                g.DrawString(total_bonuses_EW.ToString(), this.Font, this.brushText, rf2);
            }


            // Черта между бонусами и основным счетом:
            int yBorder = offset.Height + (height_Header + spaceV_Header) + spaceV_Boundary;

            if (bonus_lines > 0)
            {
                yBorder += bonus_lines * (int)size1.Height + (bonus_lines - 1) * space.Height;
            }
            g.DrawLine(pen_BorderBetween, offset.Width, yBorder, this.Width - offset.Width - 1, yBorder);
            //g.DrawLine(pen_Black, offset.Width, yBorder + 1, this.Width - offset.Width - 1, yBorder + 1); //тостая черта

            // Основные очки
            usual_lines    = 0;
            usual_lines_ns = 0;
            usual_lines_ew = 0;
            iNS            = 0;
            iEW            = 0;
            separators     = 1;
            for (int i = 0; i < ValidDealsCount; i++)
            {
                if (m_robber.ScoreArray[i].NS_down != 0)
                {
                    iNS += m_robber.ScoreArray[i].NS_down;
                    usual_lines_ns++;

                    rf1.X = offset.Width;
                    rf1.Y = offset.Height + (height_Header + spaceV_Header) + (bonus_lines + usual_lines + usual_lines_ns - 1) * (int)size1.Height + separators * (1 + 2 * spaceV_Boundary);
                    //rf1.Y++; // для толстой черты
                    if (bonus_lines + usual_lines + usual_lines_ns > 0)
                    {
                        rf1.Y += (bonus_lines + usual_lines + usual_lines_ns - 1 - separators + (is_main_separator_half ? 1 : 0)) * space.Height;
                    }
                    rf2 = SmallHelper.StringInMiddle(g, rf1, m_robber.ScoreArray[i].NS_down.ToString(), this.Font);
                    g.DrawString(m_robber.ScoreArray[i].NS_down.ToString(), this.Font, this.brushText, rf2);
                }
                else if (m_robber.ScoreArray[i].EW_down != 0)
                {
                    iEW += m_robber.ScoreArray[i].EW_down;
                    usual_lines_ew++;

                    rf1.X = offset.Width + (int)size1.Width + 2 * space.Width + 1;
                    rf1.Y = offset.Height + (height_Header + spaceV_Header) + (bonus_lines + usual_lines + usual_lines_ew - 1) * (int)size1.Height + separators * (1 + 2 * spaceV_Boundary);
                    //rf1.Y++; // для толстой черты
                    if (bonus_lines + usual_lines + usual_lines_ew > 0)
                    {
                        rf1.Y += (bonus_lines + usual_lines + usual_lines_ew - 1 - separators + (is_main_separator_half ? 1 : 0)) * space.Height;
                    }
                    rf2 = SmallHelper.StringInMiddle(g, rf1, m_robber.ScoreArray[i].EW_down.ToString(), this.Font);
                    g.DrawString(m_robber.ScoreArray[i].EW_down.ToString(), this.Font, this.brushText, rf2);
                }



                if (iEW >= 100 || iNS >= 100)
                {
                    usual_lines   += (usual_lines_ns > usual_lines_ew ? usual_lines_ns : usual_lines_ew);
                    usual_lines_ew = usual_lines_ns = 0;
                    iNS            = iEW = 0;

                    // Черта после гейма:
                    yBorder = offset.Height + (height_Header + spaceV_Header) + (bonus_lines + usual_lines) * (int)size1.Height + separators * (1 + 2 * spaceV_Boundary) + spaceV_Boundary;
                    //yBorder++; // для толстой черты
                    if (bonus_lines + usual_lines > 0)
                    {
                        yBorder += (bonus_lines + usual_lines - 1 - separators + (is_main_separator_half ? 1 : 0)) * space.Height;
                    }
                    g.DrawLine(pen_Black, offset.Width, yBorder, this.Width - offset.Width - 1, yBorder);

                    separators++;
                }
            }

            pen_Black.Dispose();
        }
        public void CleanUnnecessaryRDealsInRobber(Robber rob, int robFirstLine)
        {
            // при загрузке данных из БД не очищать роббер!
            if (loadingFromDB)
                return;

            // Найти последнюю сдачу:
            int robdealNo_last = -1;
            for (int i = 0; i < rob.ScoreArray.Count; i++)
            {
                if (rob.WhereCompleted() != -1 && rob.WhereCompleted() == i)
                {
                    robdealNo_last = i;
                    break;
                }
            }

            // Удаление лишних сдач в текущем роббере:
            if (robdealNo_last != -1)
            {
                int dealNo_delete = robdealNo_last + 1;
                while ((rob.ScoreArray.Count - dealNo_delete) > 0)
                {
                    DB_DeleteLine(robFirstLine + dealNo_delete); //даже если неудачно - продолжить цикл
                    DeleteLine(robFirstLine + dealNo_delete);
                }

                // Передвинуть нижние строки
                ReMoveUnderLine(robFirstLine + robdealNo_last);

                // Обновить таблицу
                AutoScroll_Optimize();
                this.Invalidate();
            }
        }
        public static void RobberScore(DealScoreExt out_score_ext, PairSwitcher pair, ZoneSwitcher zone, Contract contract, Result result, bool BonusForWholeRobber, Robber rob, int robdealNo, bool useOners, OnersSwitcher oners)
        {
            if (rob.WhereCompleted() != -1 && rob.WhereCompleted() < robdealNo)
            {
                out_score_ext.Clear();
            }
            else if (contract.NoContract)
            {
                out_score_ext.DealWasNotPlayed();
            }
            else if (!pair.IsDefined() || !zone.IsDefined() || !contract.IsDefined() || !result.IsDefined() || (useOners && !oners.IsDefined()))
            {
                out_score_ext.Clear();
            }
            else
            {
                bool inzone = ZoneSwitcher.IsPairInZone(pair.Pair, zone.Zone);
                bool enemy_inzone = ZoneSwitcher.IsPairInZone(pair.Pair == Pairs.EW ? Pairs.NS : Pairs.EW, zone.Zone);
                if (result.Quantity >= 0)
                {
                    // --- Если контракт сыгран ---
                    // Очки за взятки:
                    int score = contract.Quantity * (SmallHelper.WhatTrumpType(contract.Trump) == TrumpType.Minor ? 20 : 30) + (contract.Trump == CardTrump.NT ? 10 : 0);
                    if (contract.Contra)
                        score *= 2;
                    else if (contract.ReContra)
                        score *= 4;
                    // Премия за превышение взяток:
                    ArrayList bonuses = new ArrayList();
                    if (result.Quantity > 0)
                    {
                        if (contract.Contra)
                            bonuses.Add(result.Quantity * (inzone ? 200 : 100));
                        else if (contract.ReContra)
                            bonuses.Add(result.Quantity * (inzone ? 400 : 200));
                        else
                            bonuses.Add(result.Quantity * (SmallHelper.WhatTrumpType(contract.Trump) == TrumpType.Minor ? 20 : 30));
                    }
                    if (contract.Quantity == 6) //малый шлем
                    {
                        bonuses.Add(inzone ? 750 : 500);
                    }
                    else if (contract.Quantity == 7) //большой шлем
                    {
                        bonuses.Add(inzone ? 1500 : 1000);
                    }
                    // Дополнительная премия за оскорбление:
                    if (contract.Contra)
                        bonuses.Add(50);
                    else if (contract.ReContra)
                        bonuses.Add(100);

                    switch (pair.Pair)
                    {
                        case Pairs.EW:
                            out_score_ext.EW_down = score;

                            // Премия за роббер:
                            if (BonusForWholeRobber)
                            {
                                if (rob.WhereCompleted() == robdealNo)
                                    bonuses.Add(enemy_inzone ? 500 : 700);
                            }
                            // Премия за гейм:
                            else
                            {
                                if (rob.WhereCompleted() == robdealNo)
                                    bonuses.Add(500);
                                else if (rob.DoesDealMakeGame(robdealNo))
                                    bonuses.Add(200);
                            }

                            out_score_ext.EW_up = new int[bonuses.Count];
                            for (int i = 0; i < bonuses.Count; i++)
                                out_score_ext.EW_up[i] = (int)bonuses[i];
                            out_score_ext.NS_down = 0;
                            out_score_ext.NS_up = null;
                            break;
                        case Pairs.NS:
                            out_score_ext.NS_down = score;

                            // Премия за роббер:
                            if (BonusForWholeRobber)
                            {
                                if (rob.WhereCompleted() == robdealNo)
                                    bonuses.Add(enemy_inzone ? 500 : 700);
                            }
                            // Премия за гейм:
                            else
                            {
                                if (rob.WhereCompleted() == robdealNo)
                                    bonuses.Add(500);
                                else if (rob.DoesDealMakeGame(robdealNo))
                                    bonuses.Add(200);
                            }

                            out_score_ext.NS_up = new int[bonuses.Count];
                            for (int i = 0; i < bonuses.Count; i++)
                                out_score_ext.NS_up[i] = (int)bonuses[i];
                            out_score_ext.EW_down = 0;
                            out_score_ext.EW_up = null;
                            break;
                    }
                }
                else
                {
                    // --- Если контракт проигран ---
                    int enemy_score = 0;
                    for (int i = -1; i >= result.Quantity; i--)
                    {
                        if (i == -1)
                        {
                            if (contract.Contra)
                                enemy_score += (inzone ? 200 : 100);
                            else if (contract.ReContra)
                                enemy_score += (inzone ? 400 : 200);
                            else
                                enemy_score += (inzone ? 100 : 50);
                        }
                        else
                        {
                            if (contract.Contra)
                                enemy_score += (inzone ? 300 : 200);
                            else if (contract.ReContra)
                                enemy_score += (inzone ? 600 : 400);
                            else
                                enemy_score += (inzone ? 100 : 50);
                        }
                    }
                    switch (pair.Pair)
                    {
                        case Pairs.EW:
                            out_score_ext.EW_down = 0;
                            out_score_ext.EW_up = null;
                            out_score_ext.NS_down = 0;
                            out_score_ext.NS_up = new int[1] { enemy_score };
                            break;
                        case Pairs.NS:
                            out_score_ext.NS_down = 0;
                            out_score_ext.NS_up = null;
                            out_score_ext.EW_down = 0;
                            out_score_ext.EW_up = new int[1] { enemy_score };
                            break;
                    }
                }

                // Премия за онеры !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                if (useOners && oners.Choise != 0)
                {
                    int bonus_for_oners = 0;
                    if (oners.Choise == 1 || oners.Choise == 4) //4o
                        bonus_for_oners = 100;
                    else if (oners.Choise == 2 || oners.Choise == 5) //5o
                        bonus_for_oners = 150;
                    else if (oners.Choise == 3 || oners.Choise == 6) //4A
                        bonus_for_oners = 150;

                    if (oners.Choise >= 1 && oners.Choise <= 3) //премия NS
                    {
                        if (out_score_ext.NS_up == null)
                            out_score_ext.NS_up = new int[] { bonus_for_oners };
                        else
                        {
                            int[] old = out_score_ext.NS_up;
                            out_score_ext.NS_up = new int[old.Count() + 1];
                            for (int i = 0; i < old.Count(); i++)
                                out_score_ext.NS_up[i] = old[i];
                            out_score_ext.NS_up[old.Count()] = bonus_for_oners;
                        }
                    }
                    else if (oners.Choise >= 4 && oners.Choise <= 6) //премия EW
                    {
                        if (out_score_ext.EW_up == null)
                            out_score_ext.EW_up = new int[] { bonus_for_oners };
                        else
                        {
                            int[] old = out_score_ext.EW_up;
                            out_score_ext.EW_up = new int[old.Count() + 1];
                            for (int i = 0; i < old.Count(); i++)
                                out_score_ext.EW_up[i] = old[i];
                            out_score_ext.EW_up[old.Count()] = bonus_for_oners;
                        }
                    }
                }
            }
        }