Example #1
0
        private bool UpdatePlayerScores(int scoringPlayerId, int secondaryPlayerId)
        {
            var scoringPoint   = GetCurrentScore(scoringPlayerId);
            var secondaryPoint = GetCurrentScore(secondaryPlayerId);

            var newScore = Score.IncrementScore(scoringPoint);

            switch (newScore)
            {
            case Enums.Score.WinningPoint:
                SetCurrentScore(scoringPlayerId, newScore, true);

                break;

            case Enums.Score.Forty:
                if (secondaryPoint == Enums.Score.Forty)
                {
                    SetCurrentScore(scoringPlayerId, Enums.Score.Deuce);
                    SetCurrentScore(secondaryPlayerId, Enums.Score.Deuce);
                }
                else
                {
                    SetCurrentScore(scoringPlayerId, newScore);
                }
                break;

            case Enums.Score.Advantage:
                if (secondaryPoint == Enums.Score.Advantage)
                {
                    SetCurrentScore(scoringPlayerId, Enums.Score.Deuce);
                    SetCurrentScore(secondaryPlayerId, Enums.Score.Deuce);
                }
                else
                {
                    SetCurrentScore(scoringPlayerId, newScore, true);
                    SetCurrentScore(secondaryPlayerId, Enums.Score.Deuce);
                }
                break;

            default:
                SetCurrentScore(scoringPlayerId, newScore);
                break;
            }

            return(scoringPoint == Enums.Score.WinningPoint ? true : false);
        }