예제 #1
0
        public bool AreWordsValid()
        {
            bool isValid = true;

            var wordList = _gameBoard.GetWordList();

            var invalidWords = new List <GameBoard.WordCoordinate>();

            //
            // 0 here means that the board was invalid (tiles not properly placed).
            //

            if (wordList.Count == 0)
            {
                return(false);
            }


            //
            // Go through all the words and look them up in the dictionary.
            //

            foreach (var wc in wordList)
            {
                if (!_dictionary.IsAValidWord(wc._string))
                {
                    isValid = false;
                    invalidWords.Add(wc);
                }
            }


            //
            // If the board isn't valid, signal to the UI page to highlight the invalid tiles
            //

            if (!isValid)
            {
                var invalidPoints = new List <Point>();

                foreach (var wc in invalidWords)
                {
                    //
                    // Begin and End of WordCoordinates give us the two endpoints of an invalid
                    // word.  All tiles in between those must be marked invalid as well.
                    //

                    if (wc._begin.X == wc._end.X)
                    {
                        var variable = wc._begin.Y;
                        while (variable <= wc._end.Y)
                        {
                            var newPoint = new Point(wc._begin.X, variable);
                            invalidPoints.Add(newPoint);
                            variable++;
                        }
                    }
                    else if (wc._begin.Y == wc._end.Y)
                    {
                        var variable = wc._begin.X;
                        while (variable <= wc._end.X)
                        {
                            var newPoint = new Point(variable, wc._begin.Y);
                            invalidPoints.Add(newPoint);
                            variable++;
                        }
                    }
                }

                OnInvalidWordUiUpdate(invalidPoints);
            }

            return(isValid);
        }