Пример #1
0
        private MyVectorInt GetStartCoord()
        {
            MyVectorInt output = new MyVectorInt();

            if (rnd.Next(2) == 0)
            {
                if (rnd.Next(2) == 0)
                {
                    output.X = 1;
                    output.Y = 1;
                }
                else
                {
                    output.X = 1;
                    output.Y = YSize;
                }
            }
            else
            {
                if (rnd.Next(2) == 0)
                {
                    output.X = XSize;
                    output.Y = 1;
                }
                else
                {
                    output.X = XSize;
                    output.Y = YSize;
                }
            }

            return(output);
        }
Пример #2
0
        private static void ReadAndSetFieldWordCoords(Field field, string line)
        {
            string localStr = string.Empty;

            foreach (char letter in line)
            {
                if (letter == '|')
                {
                    field.WordPos.Add(new List <MyVectorInt>());
                }
                else if (letter == '/')
                {
                    field.WordPos[field.WordPos.Count - 1].Add(new MyVectorInt());
                }
                else if (letter == '_')
                {
                    MyVectorInt coord = field.WordPos[field.WordPos.Count - 1][field.WordPos[field.WordPos.Count - 1].Count - 1];
                    coord.Y = Convert.ToInt32(localStr);
                    field.WordPos[field.WordPos.Count - 1][field.WordPos[field.WordPos.Count - 1].Count - 1] = coord;
                    localStr = string.Empty;
                }
                else if (letter == ' ')
                {
                    MyVectorInt coord = field.WordPos[field.WordPos.Count - 1][field.WordPos[field.WordPos.Count - 1].Count - 1];
                    coord.Y = -10;
                    coord.X = Convert.ToInt32(localStr);
                    field.WordPos[field.WordPos.Count - 1][field.WordPos[field.WordPos.Count - 1].Count - 1] = coord;
                    localStr = string.Empty;
                }
                else
                {
                    localStr += letter;
                }
            }
        }
Пример #3
0
        private void FillFieldWithWordTemplates(bool[,] preField, List <MyVectorInt> coordList)
        {
            MyVectorInt startCoord = GetStartCoord();
            int         dir        = GetStartDirection(startCoord.X, startCoord.Y, preField);

            int[,] numField = new int[XSize, YSize];
            int  openCellNum = XSize * YSize;
            bool isGoBack    = false;
            {
                int x = startCoord.X;
                int y = startCoord.Y;
                while (openCellNum != 0)
                {
                    if (preField[x, y])
                    {
                        preField[x, y] = false;
                        openCellNum--;
                        numField[x - 1, y - 1] = XSize * YSize - openCellNum;
                        coordList.Add(new MyVectorInt(x - 1, y - 1));
                    }

                    MyVectorInt coordLocal = GetNextCellCoord(x, y, dir);

                    if (!preField[coordLocal.X, coordLocal.Y])
                    {
                        int oldDir = dir;
                        dir = FindDirection(x, y, preField);
                        if (dir == 0)
                        {
                            if (openCellNum > 0)
                            {
                                throw new Exception("На поле остались пустые ячейки, до которых невозможно добраться");
                            }
                            else
                            {
                                break;
                            }
                        }

                        if (isGoBack == false)
                        {
                            if (rnd.Next(3) == 0)
                            {
                                isGoBack = true;
                            }
                        }
                        else if (isGoBack == true)
                        {
                            if (rnd.Next(3) == 0)
                            {
                                isGoBack = false;
                            }

                            MyVectorInt coordNext  = GetNextCellCoord(x, y, dir);
                            MyVectorInt coordNext2 = GetNextCellCoord(coordNext.X, coordNext.Y, (oldDir + 1) % 4 + 1);

                            if (preField[coordNext2.X, coordNext2.Y])
                            {
                                preField[coordNext.X, coordNext.Y] = false;
                                openCellNum -= 1;
                                numField[coordNext.X - 1, coordNext.Y - 1] = XSize * YSize - openCellNum;
                                coordList.Add(new MyVectorInt(coordNext.X - 1, coordNext.Y - 1));
                                x   = coordNext2.X;
                                y   = coordNext2.Y;
                                dir = (oldDir + 1) % 4 + 1;
                            }
                            else
                            {
                                isGoBack = false;
                            }
                        }
                    }
                    else
                    {
                        x = coordLocal.X;
                        y = coordLocal.Y;
                    }
                }
            }
        }