Exemplo n.º 1
0
        public IntersectionType GetIntersectionType(CrosswordWord other)
        {
            if (other.Word.Equals(Word))
            {
                return IntersectionType.WrongIntersection;
            }

            int Ax, Ay, Bx, By, Cx, Cy, Dx, Dy;
            PositionAtIndex(0, out Ax, out Ay);
            PositionAtIndex(Word.Length - 1, out Bx, out By);
            other.PositionAtIndex(0, out Cx, out Cy);
            other.PositionAtIndex(other.Word.Length - 1, out Dx, out Dy);
            Ax--;
            Ay--;
            Bx++;
            By++;

            if (!(Intersect(Ax, Bx, Cx, Dx) && Intersect(Ay, By, Cy, Dy)))
            {
                return IntersectionType.NoIntersection;
            }

            // Rectangles are intersected. If words not then WRONG
            if (!(Intersect(Ax + 1, Bx - 1, Cx, Dx) && Intersect(Ay + 1, By - 1, Cy, Dy)))
            {
                return IntersectionType.WrongIntersection;
            }

            for (int i = 0; i < Word.Length; i++)
            {
                for (int j = 0; j < other.Word.Length; j++)
                {
                    int x1, y1, x2, y2;
                    PositionAtIndex(i, out x1, out y1);
                    other.PositionAtIndex(j, out x2, out y2);

                    if (x1 == x2 && y1 == y2)
                    {
                        if (other.Position.Orientation == Position.Orientation)
                        {
                            return IntersectionType.WrongIntersection;
                        }
                        if (!Word[i].Equals(other.Word[j]))
                        {
                            return IntersectionType.WrongIntersection;
                        }
                        return IntersectionType.CorrectIntersection;
                    }
                }
            }

            //for (int i = 0; i < Word.Length; i++)
            //{
            //    for (int j = 0; j < other.Word.Length; j++)
            //    {
            //        int x1, y1, x2, y2;
            //        PositionAtIndex(i, out x1, out y1);
            //        other.PositionAtIndex(j, out x2, out y2);

            //        if (Math.Abs(x2 - x1) + Math.Abs(y2 - y1) == 1)
            //        {
            //            return IntersectionType.WrongIntersection;
            //        }
            //    }
            //}

            return IntersectionType.NoIntersection;
        }
Exemplo n.º 2
0
        private bool IsWordInBorders(CrosswordWord word)
        {
            int x;
            int y;
            word.PositionAtIndex(word.Word.Length - 1, out x, out y);

            return x < Width && y < Height;
        }