public void ScheduleNewRound(string tournamentName, bool printNewMatches = true) { Tournament tournament = tournamentRepository.GetTournament(tournamentName); tournament.SetupTestTeams(); // Setup 8 teams Round newRound = new Round(); Match newMatch; List <Team> tempTeams = new List <Team>(tournament.GetTeams()); List <Team> newTeams = new List <Team>(); int numberOfRound = tournament.GetNumberOfRounds(); Round lastRound = null; Random rnd = new Random(); bool isRoundFinished = true; Team freeRider = null; if (numberOfRound != 0) { lastRound = tournament.GetRound(numberOfRound); isRoundFinished = tournament.GetRound(numberOfRound).IsMatchesFinished(); } if (isRoundFinished) { if (lastRound != null) { tempTeams = tournament.GetRound(numberOfRound).GetWinningTeams(); tempTeams.Add(tournament.GetRound(numberOfRound).FreeRider); } while (tempTeams.Count >= 1) { if (tempTeams.Count == 1) { freeRider = tempTeams[0]; tempTeams.RemoveAt(0); } else { newMatch = new Match(); int rndNumber1 = rnd.Next(tempTeams.Count); Team team1 = tempTeams[rndNumber1]; tempTeams.RemoveAt(rndNumber1); int rndNumber2 = rnd.Next(tempTeams.Count); Team team2 = tempTeams[rndNumber2]; tempTeams.RemoveAt(rndNumber2); newMatch.FirstOpponent = team1; newMatch.SecondOpponent = team2; newTeams.Add(team1); newTeams.Add(team2); newRound.AddMatch(newMatch); } } tournament.AddRound(newRound); tournament.GetRound(numberOfRound).SetFreeRider(freeRider); } if (printNewMatches == true) { Console.WriteLine("0-------------------------------------------0"); printLine("Turnering: " + tournamentName); printLine("Runde: " + numberOfRound + 1); printLine(newTeams.Count / 2 + " kampe"); Console.WriteLine("0-------------------------------------------0"); for (int i = 0; i < newTeams.Count; i++) { printLine(paddedText(newTeams[i].Name, 20) + " - " + paddedText(newTeams[i + 1].Name, 20)); i++; } Console.WriteLine("0-------------------------------------------0"); Console.ReadLine(); } }