Ejemplo n.º 1
0
        /// <summary>
        /// Checks the validity of the words in a row or column
        /// </summary>
        /// <param name="position">position of the row or column</param>
        /// <param name="col">True if it is a column to be checked</param>
        /// <returns>True if all words are valid words.</returns>
        public bool CheckRowOrCol(int position, bool col, ScrabbleBoard testBoard)
        {
            string[,] lettersOnBoard = testBoard.GetLetterBoard();
            int           counter = 0;
            string        charAtPos;
            string        wordSegment  = "";
            List <string> wordsToCheck = new List <string>();

            while (counter < lettersOnBoard.GetLength(col ? 1 : 0)) //find what individual words are seperated by blank space
            {
                charAtPos = (col ? lettersOnBoard[position, lettersOnBoard.GetLength(1) - 1 - counter] : lettersOnBoard[counter, position]);
                if (charAtPos == null)
                {
                    if (!wordSegment.Equals(""))
                    {
                        wordsToCheck.Add(new String(wordSegment.ToCharArray()));
                        wordSegment = "";
                    }
                }
                else
                {
                    wordSegment = wordSegment + charAtPos;
                }
                counter++;
            }
            foreach (string word in wordsToCheck) //check if the words greater than length 1 are in the dictionary
            {
                System.Diagnostics.Debug.WriteLine(word);
                if (word.Length != 1 && !dictionary.Contains(word))
                {
                    return(false);
                }
            }

            return(true);
        }