Beispiel #1
0
        /// <summary>
        /// Checks if letter given by User is correct
        /// </summary>
        /// <param name="letterToCheck"></param>
        /// <returns>boolean</returns>
        public bool IsCorrect(char letterToCheck)
        {
            if (ValidChars.Contains(letterToCheck) && !GuessedChars.Contains(letterToCheck))
            {
                for (int i = 0; i < Answer.Length; i++)
                {
                    if (Answer[i] == letterToCheck)
                    {
                        EmptyTargetWord[i] = letterToCheck;
                        Counter           += 1;
                        GuessedChars.Add(letterToCheck);
                    }
                }
                DisplayWord();

                VisualEffects.ProduceFoundLetterMessageInColor(letterToCheck, true);

                ValidChars.Remove(letterToCheck);
                return(true);
            }
            DisplayWord();
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// This method starts game and keeps track of current game session.
        /// </summary>
        // TO DO: refactor while loop into seperate method
        public void StartGame()
        {
            VisualEffects.StartGameMessage();
            var input = Console.ReadLine();
            // set number of players
            int numberOfPlayers = Convert.ToInt32(input);

            for (int i = 0; i < numberOfPlayers; i++)
            {
                VisualEffects.CenterConsoleText("Please enter name of the Player");
                var name = Console.ReadLine();
                name = Convert.ToString(name);
                Players.Add(new Player(name));
            }

            VisualEffects.StartGameMessage();
            word.GenerateDashes();
            // set current player

            CurrentPlayer = Players[CurrentPlayerIndex];


            while (true)
            {
                VisualEffects.CenterConsoleText("Press 1 to guess entire word");
                VisualEffects.CenterConsoleText("Press 2 to guess the letter");

                char choice = Console.ReadKey(true).KeyChar;

                if (choice == '1')
                {
                    string guessedWord = CurrentPlayer.ReadWordInput();
                    if (word.IsWordCorrect(guessedWord))
                    {
                        word.DisplayWord();
                        VisualEffects.CenterConsoleText($"The word {guessedWord} is Correct!");
                        int points = PointWheel.SpinWheelForCorrectWord();
                        CurrentPlayer.IncreasePoints(points);
                        EndGame();
                        break;
                    }
                    else
                    {
                        word.DisplayWord();
                        VisualEffects.CenterConsoleText($"The word {guessedWord} is Incorrect!");
                    }
                }
                else
                {
                    char letter = CurrentPlayer.ReadLetterInput();
                    if (!word.IsCorrect(letter))
                    {
                        VisualEffects.ProduceFoundLetterMessageInColor(letter, false);
                        // switch current player;
                        SwitchCurrentPlayer();
                    }
                    else
                    {
                        int points = PointWheel.SpinWheelForCorrectGuessedLetter();
                        CurrentPlayer.IncreasePoints(points);
                        if (didWin())
                        {
                            EndGame();
                            break;
                        }
                    }
                }
            }
        }