Esempio n. 1
0
        /// <summary>
        /// Method to manage tennis game.
        /// </summary>
        public void PlayGame()
        {
            try
            {
                //Display welcome message
                consoleService.DisplayWelcomeMessage();
                //Get players name
                playerA = playerService.SetFirstPlayerName(consoleService.AskForPlayerName("A"));
                playerB = playerService.SetSecondPlayerName(consoleService.AskForPlayerName("B"), playerA);

                while (true)
                {
                    //Display players points, ask them to play
                    consoleService.DisplayPlayersPoints(playerA, playerB);
                    consoleService.AskToPlay();
                    consoleService.Clear();

                    //Get point winner player name and display it
                    string pointWinnerName = pointService.GetPointWinnerName(playerA, playerB);
                    consoleService.DisplayMessage($"{pointWinnerName} won the point");
                    //Update player points points
                    pointService.UpdatePlayerPoints(playerA, playerB, pointWinnerName);

                    //Get Winner Player
                    Player winner = playerService.GetGameWinnerPlayer(playerA, playerB);
                    if (winner != null)
                    {
                        consoleService.Clear();
                        consoleService.DisplayMessage($"{winner.Name} WINS THE GAME! CONGRATS!");
                        break;
                    }
                }
            }

            catch (Exception ex)
            {
                consoleService.DisplayMessage(ex.Message);
            }
        }