Пример #1
0
        public void Points_UpdatePoints_PlayerB_WinsTheGame()
        {
            ServiceProvider serviceProvider = ServiceHelper.RegisterServices();
            IPointService   pointService    = serviceProvider.GetService <IPointService>();
            Player          playerA         = new Player("Player A");
            Player          playerB         = new Player("Player B");

            pointService.UpdatePlayerPoints(playerA, playerB, playerA.Name);
            Assert.AreEqual(Points.Fifteen, playerA.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Fifteen, playerB.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerA.Name);
            Assert.AreEqual(Points.Thirty, playerA.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Thirty, playerB.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Forty, playerB.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Game, playerB.Points);
            Assert.AreEqual(Points.Thirty, playerA.Points);
        }
Пример #2
0
        public void Points_UpdatePoints_CaseOfAdvantage()
        {
            ServiceProvider serviceProvider = ServiceHelper.RegisterServices();
            IPointService   pointService    = serviceProvider.GetService <IPointService>();
            Player          playerA         = new Player("Player A");
            Player          playerB         = new Player("Player B");

            pointService.UpdatePlayerPoints(playerA, playerB, playerA.Name);
            Assert.AreEqual(Points.Fifteen, playerA.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerA.Name);
            Assert.AreEqual(Points.Thirty, playerA.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Fifteen, playerB.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Thirty, playerB.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerA.Name);
            Assert.AreEqual(Points.Forty, playerA.Points);

            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Forty, playerB.Points);

            //Player A takes advantage
            pointService.UpdatePlayerPoints(playerA, playerB, playerA.Name);
            Assert.AreEqual(Points.Advantage, playerA.Points);
            //Point for Player B, it removes the advantage from player A
            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Forty, playerA.Points);
            //Point for Player B
            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Advantage, playerB.Points);
            //Player B wins the game
            pointService.UpdatePlayerPoints(playerA, playerB, playerB.Name);
            Assert.AreEqual(Points.Game, playerB.Points);
        }
Пример #3
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);
            }
        }
Пример #4
0
        public void Points_AlwaysWinsPlayerA()
        {
            Player          playerA         = new Player("PlayerA");
            Player          playerB         = new Player("PlayerB");
            Player          winner          = new Player();
            ServiceProvider serviceProvider = ServiceHelper.RegisterServices();
            IPointService   pointService    = serviceProvider.GetService <IPointService>();
            IPlayerService  playerService   = serviceProvider.GetService <IPlayerService>();

            while (true)
            {
                string pointWinnerName = playerA.Name;
                //Update player points points
                pointService.UpdatePlayerPoints(playerA, playerB, pointWinnerName);
                //Get Winner Player
                winner = playerService.GetGameWinnerPlayer(playerA, playerB);
                if (winner != null)
                {
                    Assert.AreEqual(playerA.Name, winner.Name);
                    break;
                }
            }
        }