Ejemplo n.º 1
0
        /// <summary>
        /// Search this node for all partial matches of a word (up to the value of WORD_SEARCH_LIMIT) and append them to the list parameter
        /// </summary>
        /// <param name="wordEnum">The partial word to match</param>
        /// <param name="solns">The list of solutions to be added to</param>
        public void WordSearch(CharEnumerator wordEnum, List <String> solns)
        {
            if (!wordEnum.MoveNext())
            {
                if (_isWord)
                {
                    solns.Add(this.ToString());
                    if (solns.Count >= WORD_SEARCH_LIMIT)
                    {
                        return;
                    }
                }

                foreach (DictNode n in Children)
                {
                    n.WordSearch(solns);
                    if (solns.Count >= WORD_SEARCH_LIMIT)
                    {
                        return;
                    }
                }
                return;
            }

            LetterUtil.Letter letter = LetterUtil.GetLetter(wordEnum.Current);
            foreach (DictNode n in Children)
            {
                if (letter == n.LetterEnum)
                {
                    n.WordSearch(wordEnum, solns);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Event handler for when the quick enter menu item is clicked. This is when you enter a series of letters to be displayed in the grid.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void QuickGridEnterMenu_Click(object sender, EventArgs e)
        {
            String result = Interaction.InputBox("Enter the letters in order with spaces in between them", "Quick Letter Entry", String.Empty);

            string[] letters = result.Split(' ');
            switch (_gridIndex)
            {
            case 0:
                throw new NotImplementedException();

            case 1:
                if (letters.Length < 16)
                {
                    if (MessageBox.Show("Not enough letters entered", "Error", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error)
                        == System.Windows.Forms.DialogResult.Retry)
                    {
                        QuickGridEnterMenu_Click(null, null);
                    }
                    return;
                }

                for (int i = 0; i < 16; i++)
                {
                    _gameGrid.SetButtonValue(i, LetterUtil.GetLetter(letters[i][0]));
                }
                break;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor used when initialising an anagram with a given word
        /// </summary>
        /// <param name="word">The word to initialise with</param>
        /// <param name="window">A reference to the parent form of this grid</param>
        public LetterGrid(String word, MainWindow window) : this(GRID_MAX_X, word.Length / GRID_MAX_X + (((word.Length % GRID_MAX_X) == 0) ? 0 : 1), window)
        {
            Options = new GameOptions(word.Length);

            CharEnumerator charEnum = word.GetEnumerator();
            int            count    = 0;

            while (charEnum.MoveNext())
            {
                SetButtonValue(count++, LetterUtil.GetLetter(charEnum.Current));
            }

            if (!Options.IsMaxAnagramLength)
            {
                SetIsAddLetter(count, true);
            }

            foreach (LetterButton[] buttons in Buttons)
            {
                foreach (LetterButton button in buttons)
                {
                    button.Sync(this);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructor used when there is no parent node, i.e. the root of the tree
        /// </summary>
        /// <param name="subword">The enumeration of the word to populate the tree</param>
        /// <param name="depth">The depth of the node</param>
        /// <param name="parent">The node immediately above this node in the tree</param>
        public DictNode(CharEnumerator subword, int depth, TreeTraverse parent) : base(parent)
        {
            _depth     = depth;
            Letter     = subword.Current;
            LetterEnum = LetterUtil.GetLetter(Letter);

            if (subword.MoveNext())
            {
                Children.Add(new DictNode(subword, _depth + 1, this));
                _isWord = false;
            }
            else
            {
                _isWord = true;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Perform a partial word search. This will find all words (up to a certain number) that start with the first parameter.
        /// </summary>
        /// <param name="partialWord">The start of the words to search for</param>
        /// <returns>A list of matched words</returns>
        public List <String> WordSearch(String partialWord)
        {
            List <String> solns = new List <string>();

            CharEnumerator wordEnum = partialWord.GetEnumerator();

            if (!wordEnum.MoveNext())
            {
                return(solns);
            }

            LetterUtil.Letter letter = LetterUtil.GetLetter(wordEnum.Current);
            foreach (DictNode n in Children)
            {
                if (letter == n.LetterEnum)
                {
                    n.WordSearch(wordEnum, solns);
                }
            }

            return(solns);
        }