예제 #1
0
        public LetterCheck GetCoordinates(LetterCheck lett, LastWordEntered entry, Coordinate cords)
        {
            Dictionary <Coordinate, char> coordsinExistingLetter = entry.LetterCords;

            //get the coords of the letter in the existing word so we know where to start
            lett.ExistingLetterRow    = cords.Row;
            lett.ExistingLetterColumn = cords.Column;
            CoordsPointer coordsP = new CoordsPointer(cords);

            TestTheLetter(coordsP, lett);

            return(lett);
        }
예제 #2
0
        public Word TestTheLetterInWord(LetterAttributes lett, CoordsPointer c, Word aName, Word entry)
        {
            //check the grid for empty tiles and space for the word
            if (lett.IterationsLeftOrAbove == 0) //check if the intersecting letter in the word to be added is at the start
            {
                if (entry.IsHorizontal == true)
                {
                    for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter
                    {
                        //check below the letter
                        if (Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.BelowLetter, c.LeftOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0')
                        {
                            aName.IsValid    = true;
                            aName.IsVertical = true;
                            c.BelowLetter++;   //goin down so plus the index by 1
                            continue;
                        }
                        else
                        {
                            lett.Valid = false;
                            return(aName);
                        }
                    }
                }
            }
            else
            {
                if (entry.IsHorizontal == true)
                {
                    for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter
                    {
                        if (Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.BelowLetter, c.LeftOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0')
                        {
                        }
                        else
                        {
                            lett.Valid = false;
                            return(aName);
                        }
                    }
                }
            }

            return(aName);
        }
예제 #3
0
        public Word CheckLettersInName(Word aName, char letterInExistingWord, Word entry, Coordinate letterCords)
        {
            var letterList = aName.LettersInWord.ToList();

            foreach (var letter in letterList)
            {
                LetterAttributes lett = new LetterAttributes(letterList.IndexOf(letter), letterList.Count, letter);
                lett.ExistingLetterRow    = letterCords.Row;
                lett.ExistingLetterColumn = letterCords.Column;
                CoordsPointer coordsP = new CoordsPointer(letterCords);

                if (lett.Letter == letterInExistingWord)
                {
                    TestTheLetterInWord(lett, coordsP, aName, entry);
                }
                else
                {
                    continue;
                }
            }

            return(entry);
        }
예제 #4
0
        public LetterCheck TestTheLetter(CoordsPointer c, LetterCheck lett)
        {
            //check the grid for empty tiles and space for the word
            if (lett.IterationsLeftOrAbove == 0) //check if the intersecting letter in the word to be added is at the start
            {
                //check if word to be inserted is a horizontal word, also lets you know if the existing word in the grid is vertical
                if (c.RightOfLetter < Grid.GetUpperBound(1) && Grid[lett.ExistingLetterRow, c.RightOfLetter] == '\0' && Grid[lett.ExistingLetterRow, c.LeftOfLetter] == '\0')
                {
                    for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter
                    {
                        if (Grid[lett.ExistingLetterRow, c.RightOfLetter] == '\0' && Grid[c.AboveLetter, c.RightOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0')
                        {
                            lett.Valid        = true;
                            lett.IsHorizontal = true;
                            c.RightOfLetter++;   //goin right so plus the index by 1
                            continue;
                        }
                        else
                        {
                            lett.Valid = false;
                            return(lett);
                        }
                    }

                    return(lett);
                }
                //check if word to be inserted is a vertical word, also lets you know if the existing word in the grid is horizontal
                if (lett.ExistingLetterColumn < Grid.GetUpperBound(1) && Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.AboveLetter, lett.ExistingLetterColumn] == '\0')
                {
                    for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter
                    {
                        if (Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.BelowLetter, c.LeftOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0')
                        {
                            lett.Valid      = true;
                            lett.IsVertical = true;
                            c.BelowLetter++;   //goin down so plus the index by 1
                            continue;
                        }
                        else
                        {
                            lett.Valid = false;
                            return(lett);
                        }
                    }

                    return(lett);
                }
            }

            //check if word to be inserted is a horizontal word, also lets you know if the existing word in the grid is vertical
            if (c.RightOfLetter < Grid.GetUpperBound(1) && Grid[lett.ExistingLetterRow, c.LeftOfLetter] == '\0' && Grid[lett.ExistingLetterRow, c.RightOfLetter] == '\0')
            {
                //check right  of letter the letter
                for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter
                {
                    if (Grid[lett.ExistingLetterRow, c.RightOfLetter] == '\0' && Grid[c.AboveLetter, c.RightOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0')
                    {
                        lett.Valid        = true;
                        lett.IsHorizontal = true;
                        c.RightOfLetter++;   //goin right so plus the index by 1
                        continue;
                    }
                    else
                    {
                        lett.Valid = false;
                        return(lett);
                    }
                }

                //check left of letter
                for (int x = 0; x < lett.IterationsLeftOrAbove + 1; x++) //add an extra move to the left for white space around the letter
                {
                    if (Grid[lett.ExistingLetterRow, c.LeftOfLetter] == '\0' && Grid[c.AboveLetter, c.LeftOfLetter] == '\0' && Grid[c.BelowLetter, c.LeftOfLetter] == '\0')
                    {
                        lett.Valid        = true;
                        lett.IsHorizontal = true;
                        c.LeftOfLetter--;   //goin left so minus the index by 1
                        continue;
                    }
                    else
                    {
                        lett.Valid = false;
                        return(lett);
                    }
                }
            }
            //check if word to be inserted is a vertical word, also lets you know if the existing word in the grid is horizontal
            else if (lett.ExistingLetterColumn < Grid.GetUpperBound(1) && Grid[c.AboveLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0')
            {
                //check below of the letter
                for (int x = 0; x < lett.IterationsRightOrBelow + 1; x++) //add an extra move to the left for white space around the letter
                {
                    if (Grid[c.BelowLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.BelowLetter, c.LeftOfLetter] == '\0' && Grid[c.BelowLetter, c.RightOfLetter] == '\0')
                    {
                        lett.Valid      = true;
                        lett.IsVertical = true;
                        c.BelowLetter++;   //goin down so plus the index by 1
                        continue;
                    }
                    else
                    {
                        lett.Valid = false;
                        return(lett);
                    }
                }

                //check above of the letter
                for (int x = 0; x < lett.IterationsLeftOrAbove + 1; x++) //add an extra move to the left for white space around the letter
                {
                    if (Grid[c.AboveLetter, lett.ExistingLetterColumn] == '\0' && Grid[c.AboveLetter, c.LeftOfLetter] == '\0' && Grid[c.AboveLetter, c.RightOfLetter] == '\0')
                    {
                        lett.Valid      = true;
                        lett.IsVertical = true;
                        c.AboveLetter--;   //goin up so minus the index by 1
                        continue;
                    }
                    else
                    {
                        lett.Valid = false;
                        return(lett);
                    }
                }
            }

            return(lett);
        }