Exemplo n.º 1
0
        //този метод е обратният на ToDataField

        public void GetOldGame(string dataField)
        {
            int subIndexStart = 0;

            foreach (Cell cell in this.cells)
            {
                string subStringCell = dataField.Substring(subIndexStart, 2);
                if (subStringCell.StartsWith("2"))
                {
                    cell.CellValue = Convert.ToInt32(subStringCell) - 20;
                    cell.Generated = true;
                    cell.Enabled   = false;
                }
                else
                {
                    cell.CellValue = Convert.ToInt32(subStringCell) - 10;
                }
                if (cell.CellValue == 0)
                {
                    cell.Text = string.Empty;
                }
                else
                {
                    cell.Text = Convert.ToString(cell.CellValue);
                }
                subIndexStart = subIndexStart + 2;
                int indexSector = AllMatrices.SectorIndex(cell);
                AllMatrices.SetValueInArray(cell, indexSector);
            }
        }
Exemplo n.º 2
0
        //При вече въведена стоийност трябва да проверим да ли се пофтаря
        //За да не ни се счупи кода ако полето е празно има  try и catch
        //В catch се задава стйност 0 на пропъртито CellValue.
        //след това имаме проверка за повторение в сектора ако имаме фоновия
        //цвят става червен.
        //По същия начин и за съседните сектори
        //Използваме методите от класа AllMatrices

        protected override void OnLeave(EventArgs e)
        {
            base.OnLeave(e);
            BackColor = Color.White;
            try
            {
                CellValue = Convert.ToInt32(Text);
            }
            catch (Exception)
            {
                CellValue = 0;
                AllMatrices.SetValueInArray(this, AllMatrices.SectorIndex(this));
                return;
            }

            AllMatrices gameArraysCheaks = new AllMatrices();

            if (!gameArraysCheaks.CheckSector(this))
            {
                BackColor = Color.Red;
            }

            else if (!gameArraysCheaks.CneckInAllMatrices(this))
            {
                BackColor = Color.Red;
            }
        }
Exemplo n.º 3
0
        //Преди да се генерира нова игра трябва всеки сектор
        //да се върне към първоначалните си настройки

        public static void ClearSector(Sector sector)
        {
            foreach (Cell cell in sector.cells)
            {
                cell.CellValue = 0;
                cell.Text      = string.Empty;
                cell.Generated = false;
                cell.Enabled   = true;

                int indexSector = AllMatrices.SectorIndex(cell);
                AllMatrices.SetValueInArray(cell, indexSector);
            }
        }
Exemplo n.º 4
0
        //Статичен метод който се използва от класа Generator
        //Подобен е на кода в тялото на OnLeave но е статичен и
        //връща true или false

        static public bool GeneratorCheck(Cell cell)
        {
            AllMatrices gameArraysCheaks = new AllMatrices();

            if (!gameArraysCheaks.CheckSector(cell))
            {
                return(false);
            }
            else if (!gameArraysCheaks.CneckInAllMatrices(cell))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 5
0
        //Този клас се дефинира в кода на формата. Има само една стасична
        //функция с име Random приемаща 1 параметър от клас Sector.
        //Неговата функция е да генерира с готовия клас Random
        //стойноста на случайна клетка от сектора и да провери със статичните
        //методи от класа AllMatrices и методите на класа Cell

        static public void Random(Sector sector)
        {
            Random random = new Random();

            //В секи сектор клетките който
            //ще се генерират имат различен брой

            int allNumbersInSector = 0;

            while (allNumbersInSector < 3)
            {
                int cellIndex = random.Next(0, 8);
                int value     = random.Next(0, 9);

                Cell cellRandom = null;
                cellRandom = sector.cells[cellIndex];

                int sectorIndex = AllMatrices.SectorIndex(cellRandom);

                cellRandom.CellValue = value;

                if (Cell.GeneratorCheck(cellRandom))            //Генератора може няколко пъти да повтори една и съща клетка
                {                                               //но със различна стойност заради това са изредени всички пропъртита
                    cellRandom.Enabled   = false;
                    cellRandom.Generated = true;
                    cellRandom.Text      = Convert.ToString(value);
                    allNumbersInSector++;
                }
                else
                {
                    cellRandom.Enabled   = true;
                    cellRandom.Generated = false;
                    allNumbersInSector   = 0;
                    cellRandom.Text      = "";
                    cellRandom.CellValue = 0;
                    AllMatrices.SetValueInArray(cellRandom, sectorIndex);
                }
            }
        }