Esempio n. 1
0
        public Word AddingToVerticalWord(Word name, LettersInWord letterInExistingWord, Word lastWord)
        {
            Movement move = new Movement(letterInExistingWord.Coords.Row, letterInExistingWord.Coords.Column);

            name.IndexOfIntersectingLetter = Array.IndexOf(name.LettersInWordArray, letterInExistingWord.Letter);


            string leftArray  = name.Element.Substring(0, name.IndexOfIntersectingLetter);
            string rightArray = name.Element.Substring(name.IndexOfIntersectingLetter + 1);


            if (leftArray.Length > 0 && rightArray.Length > 0)
            {
                //check left hand side of word
                for (int i = leftArray.Length - 1; i > -1; i--)
                {
                    ValidateAddingToVerticalWord.ValidateLeftOne(move, Grid, leftArray[i], name);
                    if (move.IsValid == true)
                    {
                        name.IsValid      = true;
                        name.IsHorizontal = true;
                        move.LeftOfLetter--;
                    }
                    else
                    {
                        name.IsValid = false;
                        return(name);
                    }
                }

                //check right hand side of word
                for (int i = rightArray.Length - 1; i > -1; i--)
                {
                    ValidateAddingToVerticalWord.ValidateRightOne(move, Grid, rightArray[i], name);
                    if (move.IsValid == true)
                    {
                        name.IsValid      = true;
                        name.IsHorizontal = true;
                        move.RightOfLetter++;
                    }
                    else
                    {
                        name.IsValid = false;
                        return(name);
                    }
                }
            }

            if (leftArray.Length == 0 && rightArray.Length > 0)
            {
                for (int i = rightArray.Length - 1; i > -1; i--)
                {
                    ValidateAddingToVerticalWord.ValidateRightOne(move, Grid, rightArray[i], name);
                    if (move.IsValid == true)
                    {
                        name.IsValid      = true;
                        name.IsHorizontal = true;
                        move.RightOfLetter++;
                    }
                    else
                    {
                        name.IsValid = false;
                        return(name);
                    }
                }
            }

            if (leftArray.Length > 0 && rightArray.Length == 0)
            {
                for (int i = leftArray.Length - 1; i > -1; i--)
                {
                    ValidateAddingToVerticalWord.ValidateLeftOne(move, Grid, leftArray[i], name);
                    if (move.IsValid == true)
                    {
                        name.IsValid      = true;
                        name.IsHorizontal = true;
                        move.LeftOfLetter--;
                    }
                    else
                    {
                        name.IsValid = false;
                        return(name);
                    }
                }
            }

            return(name);
        }
Esempio n. 2
0
        public Word AddingToHorizonatalWord(Word name, LettersInWord letterInExistingWord, Word lastWord)
        {
            Movement move = new Movement(letterInExistingWord.Coords.Row, letterInExistingWord.Coords.Column);

            name.IndexOfIntersectingLetter = Array.IndexOf(name.LettersInWordArray, letterInExistingWord.Letter);

            string aboveArray = name.Element.Substring(0, name.IndexOfIntersectingLetter);
            string belowArray = name.Element.Substring(name.IndexOfIntersectingLetter + 1);

            if (aboveArray.Length > 0 && belowArray.Length > 0)
            {
                for (int i = aboveArray.Length - 1; i > -1; i--)
                {
                    ValidateAddingToHorizontalWord.ValidateAboveOne(move, Grid, aboveArray[i], name);
                    if (move.IsValid == true)
                    {
                        name.IsValid    = true;
                        name.IsVertical = true;
                        move.AboveLetter--;
                    }
                    else
                    {
                        name.IsValid = false;
                        return(name);
                    }
                }

                for (int i = 0; i < belowArray.Length; i++)
                {
                    ValidateAddingToHorizontalWord.ValidateBelowOne(move, Grid, belowArray[i], name);
                    if (move.IsValid == true)
                    {
                        name.IsValid    = true;
                        name.IsVertical = true;
                        move.BelowLetter++;
                    }
                    else
                    {
                        name.IsValid = false;
                        return(name);
                    }
                }
            }

            if (aboveArray.Length == 0 && belowArray.Length > 0)
            {
                for (int i = 0; i < belowArray.Length; i++)
                {
                    ValidateAddingToHorizontalWord.ValidateBelowOne(move, Grid, belowArray[i], name);
                    if (move.IsValid == true)
                    {
                        name.IsValid    = true;
                        name.IsVertical = true;
                        move.BelowLetter++;
                    }
                    else
                    {
                        name.IsValid = false;
                        return(name);
                    }
                }
            }

            if (aboveArray.Length > 0 && belowArray.Length == 0)
            {
                for (int i = aboveArray.Length - 1; i > -1; i--)
                {
                    ValidateAddingToHorizontalWord.ValidateAboveOne(move, Grid, aboveArray[i], name);
                    if (move.IsValid == true)
                    {
                        name.IsValid    = true;
                        name.IsVertical = true;
                        move.AboveLetter--;
                    }
                    else
                    {
                        name.IsValid = false;
                        return(name);
                    }
                }
            }


            return(name);
        }