示例#1
0
        /// <summary>
        /// Calculates the score of the players.
        /// </summary>
        /// <param name="winner">The winner of the point.</param>
        /// <param name="loser">The loser of the point.</param>
        private void Score(Player winner, Player loser)
        {
            switch (winner.Score)
            {
            case Tennis.Score.Love:
            case Tennis.Score.Fifteen:
            case Tennis.Score.Thirty:
            case Tennis.Score.Advantage:
                winner.IncreaseScore();
                break;

            case Tennis.Score.Forty:
                if (loser.Score <= Tennis.Score.Thirty)
                {
                    // Other player has either 0, 15, 30 therefore, 2 point lead as we are adv. This player has won the game.
                    // Increase score twice as we're setting score to game, not advantage.
                    winner.SetScoreToGame();
                }
                else if (loser.Score.Equals(Tennis.Score.Forty))
                {
                    // Increase point to advantage.
                    winner.IncreaseScore();
                }
                else if (loser.Score.Equals(Tennis.Score.Advantage))
                {
                    // Back to deuce.
                    loser.DecreaseScore();
                }
                break;

            default:
                throw new InvalidEnumArgumentException("Invalid enum arguement.");
            }

            PrintScore(winner, loser);
        }