Allow users to check the word before they play the word

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
        private static string GetChoice()
        {
            string Choice;
            Console.WriteLine();
            Console.WriteLine("Either:");
            Console.WriteLine("     enter the word you would like to play OR");
            Console.WriteLine("     press 1 to display the letter values OR");
            Console.WriteLine("     press 2 to check if word is valid OR");
            Console.WriteLine("     press 4 to view the tile queue OR");
            Console.WriteLine("     press 7 to view your tiles again OR");
            Console.WriteLine("     press 0 to fill hand and stop the game.");
            Console.Write("> ");
            Choice = Console.ReadLine();
            Console.WriteLine();
            Choice = Choice.ToUpper();
            return Choice;
        }

This is adding option 2 which will then let the user check if a word is valid or not without using their turn.

            while (!ValidChoice)
            {
                Choice = GetChoice();
                if (Choice == "1")
                {
                    DisplayTileValues(TileDictionary, AllowedWords);
                }
                else if (Choice == "2")
                {
                    bool WordCheck = false;
                    Console.WriteLine("Enter word");
                    Choice = Console.ReadLine();
                    Choice = Choice.ToUpper();
                    //Choice = GetChoice();
                    if (Choice.Length == 0)
                    {
                        WordCheck = false;
                    }
                    else
                    {
                        WordCheck = CheckWordIsInTiles(Choice, PlayerTiles);
                    }
                    if (WordCheck)
                    {
                        WordCheck = CheckWordIsValid(Choice, AllowedWords);
                        if (WordCheck)
                        {
                            Console.WriteLine();
                            Console.WriteLine("Valid word");
                            Console.WriteLine();

                        }
                    }
                    else if (WordCheck == false)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Not a valid attempt");
                        Console.WriteLine();
                    }
                    DisplayTilesInHand(PlayerTiles);
                }

This is the code to check if the word is valid.