Beispiel #1
0
        /*
         * Runs the word finder algorithm and launches the ShowPathsForm.
         */
        private void RunWordFinder(Grid <Tile> grid)
        {
            // Run the word finder algorithm.
            WordFinder           finder     = new WordFinder(Program.Dictionary, grid);
            List <WordamentPath> foundPaths = finder.FindWordsWithPaths(MinimumWordLength);

            // If it's a speed round, sort by ascending path length. Otherwise, sort by
            // descending total score.
            if (IsSpeedRound)
            {
                foundPaths.Sort((a, b) => a.Word.Length.CompareTo(b.Word.Length));
            }
            else
            {
                foundPaths.Sort((a, b) => - a.TotalScore.CompareTo(b.TotalScore));
            }

            if (foundPaths.Count == 0)
            {
                // Display an error message
                PopupDialog noResultsDialog = new PopupDialog(
                    "Error",
                    "We could not find any words on the grid. Be sure that you specified each tile correctly.",
                    this.Location,
                    false);
                noResultsDialog.ShowDialog();
            }
            else
            {
                // Launch the next window
                ShowPathsForm pathsForm = new ShowPathsForm(foundPaths, RoundNum);
                pathsForm.StartPosition = FormStartPosition.Manual;
                pathsForm.Location      = this.Location;
                pathsForm.FormClosed   += new FormClosedEventHandler(
                    (object obj, FormClosedEventArgs args) => { ReceivedFocus(); });

                this.Hide();
                pathsForm.Show();
            }
        }