Exemplo n.º 1
0
        public string ReadWordInput()
        {
            Console.Write("Please guess a word: ");
            string userInput = Console.ReadLine();

            Console.WriteLine();
            VisualEffects.CenterConsoleText($"You have entered {userInput}");
            return(userInput);
        }
Exemplo n.º 2
0
        public char ReadLetterInput()
        {
            VisualEffects.CenterConsoleText("Please guess a letter");
            ConsoleKeyInfo userInput = Console.ReadKey(true);

            Console.WriteLine();
            VisualEffects.CenterConsoleText($"You have entered {userInput.KeyChar}");

            return(userInput.KeyChar);
        }
Exemplo n.º 3
0
 public void SwitchCurrentPlayer()
 {
     if (CurrentPlayerIndex + 1 == Players.Count)
     {
         CurrentPlayerIndex = 0;
         CurrentPlayer      = Players[CurrentPlayerIndex];
     }
     else
     {
         CurrentPlayer = Players[++CurrentPlayerIndex];
     }
     VisualEffects.CenterConsoleText($"Switching Player. Player {CurrentPlayer.Name}, it's your turn");
 }
Exemplo n.º 4
0
 /// <summary>
 /// Ends the game.
 /// </summary>
 public void EndGame()
 {
     // TODO: edit message for winner
     VisualEffects.CenterConsoleText($"{CurrentPlayer.Name} won with {CurrentPlayer.Points} points!");
     VisualEffects.EndGameMessage();
 }
Exemplo n.º 5
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;
                        }
                    }
                }
            }
        }