示例#1
0
 private void initGame(int i_NumberOfGuesses)
 {
     m_Board = new Board(i_NumberOfGuesses);
     m_Board.PrintBoard();
     m_Letters = new RangeOfLetters();
     setRandomSolution();
     m_NewUserGuess = new UserGuess(k_SizeOfGuesses, m_Letters.m_ListOfLetterToChoose);
 }
示例#2
0
        public void UpdateGuessFromUser(UserGuess i_GuessFromUser, char[] i_WantedSolution)
        {
            bool invalidGuess = true;

            while (invalidGuess)
            {
                invalidGuess = false;
                string inputStringFromUser = Console.ReadLine();
                while (inputStringFromUser == null)
                {
                    Console.WriteLine("Invalid input please enter 4 charecters between A-H.");
                    inputStringFromUser = Console.ReadLine();
                }

                bool userDecideToQuit = inputStringFromUser[0] == 'q' || inputStringFromUser[0] == 'Q';
                if (userDecideToQuit)
                {
                    break;
                }

                for (int i = 0; i < inputStringFromUser.Length; i++)
                {
                    bool validString       = CheckIfContain(inputStringFromUser[i]);
                    bool validStringLength = (inputStringFromUser.Length == 4);
                    if (!validString || !validStringLength)
                    {
                        invalidGuess = true;
                        Console.WriteLine();
                        Console.WriteLine("Invalid input please enter 4 charecters between A-H.");
                        break;
                    }

                    // convert into char array
                    char[] newGuess = inputStringFromUser.ToCharArray();
                    removeLetterFromList(inputStringFromUser[i]);
                    i_GuessFromUser.SetGuess(newGuess);
                    i_GuessFromUser.setFeedBack(new String(i_GuessFromUser.GetGuess()).ToUpper().ToCharArray(), i_WantedSolution);
                }
            }
        }