public static string GetScore(IPlayer player1, IPlayer player2, IMatchKeeper matchKeeper, ScoreType scoreType) { if (scoreType == ScoreType.Current) { Enums.Score currentPoint; Enums.Score currentOppPoint; var p1IsServing = matchKeeper.CurrentServingPlayerId == player1.Id; if (p1IsServing) { currentPoint = matchKeeper.GetCurrentScore(player1.Id); currentOppPoint = matchKeeper.GetCurrentScore(player2.Id); } else { currentPoint = matchKeeper.GetCurrentScore(player2.Id); currentOppPoint = matchKeeper.GetCurrentScore(player1.Id); } if (currentPoint == Enums.Score.WinningPoint || currentPoint == Enums.Score.Advantage) { return(currentPoint == Enums.Score.WinningPoint ? $"Win for {player1.Name}" : $"Advantage {player1.Name}"); } if (currentOppPoint == Enums.Score.WinningPoint || currentOppPoint == Enums.Score.Advantage) { return(currentOppPoint == Enums.Score.WinningPoint ? $"Win for {player2.Name}" : $"Advantage {player2.Name}"); } return(GetScoreString(currentPoint, currentOppPoint)); } else { return(GetScoreString(player1, player2, matchKeeper)); } }
private static string GetScoreString(IPlayer player1, IPlayer player2, IMatchKeeper matchKeeper) { var sb = new StringBuilder(); sb.Append($"{(player1.Name.Length > 10 ? player1.Name.Remove(10) : player1.Name)} - \t"); sb.Append($"{(int)matchKeeper.GetCurrentScore(player1.Id)}\t"); var longScore = BuildScore(player1.Id, matchKeeper); sb.Append($"{longScore}\r\n"); sb.Append($"{(player2.Name.Length > 10 ? player2.Name.Remove(10) : player2.Name)} - \t"); sb.Append($"{(int)matchKeeper.GetCurrentScore(player2.Id)}\t"); longScore = BuildScore(player2.Id, matchKeeper); sb.Append($"{longScore}\r\n"); return(sb.ToString()); }