Exemplo n.º 1
0
 public TennisService()
 {
     player1 = new Player()
     {
         Id = 1, Name = "Nadal", PlayerGamePoint = GamePoint.zero
     };
     player2 = new Player()
     {
         Id = 2, Name = "Federer", PlayerGamePoint = GamePoint.zero
     };
     score = new PlayerScore(player1, player2);
 }
Exemplo n.º 2
0
 public Score Increment(int id, int sp1, int sp2)
 {
     player1 = new Player()
     {
         Id = 1, Name = "Nadal", PlayerGamePoint = (GamePoint)sp1
     };
     player2 = new Player()
     {
         Id = 2, Name = "Federer", PlayerGamePoint = (GamePoint)sp2
     };
     score = new PlayerScore(player1, player2);
     return(id == 1 ? score.Increment(player1) : score.Increment(player2));
 }
Exemplo n.º 3
0
        public Score Increment(Player player)
        {
            Score score = null;
            var   diff  = Math.Abs((int)Player1.PlayerGamePoint - (int)Player2.PlayerGamePoint);

            if ((int)player.PlayerGamePoint < 3)
            {
                player.PlayerGamePoint += 1;
                score = player.Id == 1 ? new PlayerScore(player, Player2) :
                        new PlayerScore(Player1, player);
            }
            else
            {
                if (diff == 0)
                {
                    if (player.Id == Player1.Id)
                    {
                        Player1.PlayerGamePoint = GamePoint.Advantage;
                        Player2.PlayerGamePoint = GamePoint.Deuce;
                    }
                    else
                    {
                        Player1.PlayerGamePoint = GamePoint.Deuce;
                        Player2.PlayerGamePoint = GamePoint.Advantage;
                    }
                }
                else
                {
                    if (player.Id == Player1.Id)
                    {
                        Player1.PlayerGamePoint = Player2.PlayerGamePoint = Player1.PlayerGamePoint > Player2.PlayerGamePoint ? GamePoint.zero : GamePoint.Deuce;
                    }
                    else
                    {
                        Player1.PlayerGamePoint = Player2.PlayerGamePoint = Player1.PlayerGamePoint > Player2.PlayerGamePoint ? GamePoint.Deuce : GamePoint.zero;
                    }
                }

                score = new PlayerScore(Player1, Player2);
            }
            return(score);
        }