private static void PlayerAssignHelper(Tournament tournament, IEnumerable<Player> players, GameTypes gameTypes, int teamCount) { var randomizedPlayers = players.OrderBy(p => Guid.NewGuid()).ToList(); switch (gameTypes) { case GameTypes.Singles: tournament.AddPlayers(randomizedPlayers.GetRange(0, teamCount)); break; case GameTypes.Doubles: for (int i = 0; i < teamCount*2; i += 2) { tournament.AddPlayers(randomizedPlayers[i], randomizedPlayers[i + 1]); } break; case GameTypes.Both: tournament.AddPlayers(randomizedPlayers.GetRange(0, teamCount/2)); for (int i = teamCount/2; i < teamCount + teamCount/2; i += 2) { tournament.AddPlayers(randomizedPlayers[i], randomizedPlayers[i + 1]); } break; default: throw new ArgumentOutOfRangeException(nameof(gameTypes), gameTypes, null); } }
public void ListMatches(Tournament tournament) { foreach (var match in tournament.Matches) { Console.WriteLine("---Players---"); if (!match.IsDouble) { Console.WriteLine($"{match.Team1.Player1.FirstName} {match.Team1.Player1.MiddleName} {match.Team1.Player1.LastName} (VS) {match.Team2.Player1.FirstName} {match.Team2.Player1.MiddleName} {match.Team2.Player1.LastName}"); } else { Console.WriteLine($"{match.Winner.Player1.FirstName} {match.Winner.Player1.MiddleName} {match.Winner.Player1.LastName} & {match.Winner.Player2.FirstName} {match.Winner.Player2.MiddleName} {match.Winner.Player2.LastName}"); Console.WriteLine($"{match.Team1.Player1.FirstName} {match.Team1.Player1.MiddleName} {match.Team1.Player1.LastName} & {match.Team1.Player2.FirstName} {match.Team1.Player2.MiddleName} {match.Team1.Player2.LastName} (VS) {match.Team2.Player1.FirstName} {match.Team2.Player1.MiddleName} {match.Team2.Player1.LastName} & {match.Team2.Player2.FirstName} {match.Team2.Player2.MiddleName} {match.Team2.Player2.LastName}"); } Console.WriteLine("---Match Type---"); Console.WriteLine(match.MatchType); Console.WriteLine("---Referee---"); Console.WriteLine(match.Referee.FirstName); Console.WriteLine("---Round---"); Console.WriteLine(match.Round); Console.WriteLine("---Set Results---"); foreach (var result in match.SetResults) { Console.WriteLine(result.Item1 + ":" + result.Item2); } Console.WriteLine("___________________________________________________________"); } }
public void ListPlayers(Tournament tournament) { foreach (var player in tournament.ListPlayers()) { Console.WriteLine($"{player.FirstName} {player.MiddleName} {player.LastName} (Age: {player.GetAge()})"); } }
public void DisplayMenu(Tournament selectedTournament) { var selectedTournamentText = selectedTournament == null ? "None" : selectedTournament.Name; var selectedTournamentStatus = selectedTournament != null && selectedTournament.IsOver() ? "Completed" : "In progress"; Console.WriteLine($@" _______________|MENU|________________________ | | | Choose what you want to do: | | 1) Create a new tournament. | | 2) List all tournaments. | | 3) Select a tournament. | | 4) Play selected tournament. | | 5) List winner(s) of selected tournament. | | 6) List all matches in selected tournament. | | 7) List all players in selected tournament. | | ESC) Exit. | |_____________________________________________| SELECTED TOURNAMENT: {selectedTournamentText} ({selectedTournamentStatus})"); }
public void ListWinners(Tournament tournament) { foreach (var team in tournament.Winner) { if (!team.IsDouble) { Console.WriteLine($"{team.Player1.FirstName} {team.Player1.MiddleName} {team.Player1.LastName}"); } else { Console.WriteLine($"{team.Player1.FirstName} {team.Player1.MiddleName} {team.Player1.LastName} & {team.Player2.FirstName} {team.Player2.MiddleName} {team.Player2.LastName}"); } } }