コード例 #1
0
        //Allow to input a guess from outside od the dll (from the ui)
        public bool Guess(char letter)
        {
            bool res = false;

            //validate the input
            if (!ValidateLetter(letter))
            {
                //if not valid, do not cotinue and throw an argument exception
                throw new ArgumentException($"{letter} is not a valid English letter");
            }
            //use upper case letters only
            char upperLetter = char.ToUpper(letter);

            //check if the game is active and that the letter is available to guess
            if (IsGameActive && GamePlayer.IsAvaileableToGuess(upperLetter))
            {
                //guess the letter in two places,
                //in the word model
                //res will be the flag that will tell the user of the class if he was successful in his guess
                res = WordToGuess.Guess(upperLetter);
                //in the Player model
                GamePlayer.Guess(upperLetter, res);

                //check if the game is done(player guessed the entire word)
                if (WordToGuess.IsComplete)
                {
                    //acitvate the win game method(holds instructions for the end of the game)
                    WinGame();
                    //return sucsessfull guess and exit the method
                    return(true);
                }

                //the guess was unsuccessful
                if (!res)
                {
                    //update the hang man status
                    HangedManStatus++;
                }
            }
            return(res);
        }