Ejemplo n.º 1
0
        public void ScheduleNewRound(string tournamentName, bool printNewMatches = true)
        {
            Tournament tournament = tournamentRepository.GetTournament(tournamentName);
            //tournament.SetupTestTeams(); // Bruges til at teste menuen, udkommenter ved test
            Round newRound = new Round();
            Match newMatch;

            List <Team> tempTeams;
            List <Team> newTeams = new List <Team>();

            int    numberOfRound   = tournament.GetNumberOfRounds();
            Round  lastRound       = null;
            Random random          = new Random();
            bool   isRoundFinished = true;
            Team   freeRider       = null;

            if (numberOfRound != 0)
            {
                numberOfRound--;
                lastRound       = tournament.GetRound(numberOfRound);
                isRoundFinished = tournament.GetRound(numberOfRound).IsMatchesFinished();
            }

            if (isRoundFinished)
            {
                if (lastRound != null)
                {
                    tempTeams = new List <Team>(tournament.GetRound(numberOfRound).GetWinningTeams());
                    if (tournament.GetRound(numberOfRound).FreeRider != null)
                    {
                        tempTeams.Add(tournament.GetRound(numberOfRound).FreeRider);
                    }
                }
                else
                {
                    tempTeams = new List <Team>(tournament.GetTeams());
                }

                while (tempTeams.Count >= 1)
                {
                    if (tempTeams.Count == 1)
                    {
                        freeRider = tempTeams[0];
                        tempTeams.RemoveAt(0);
                    }
                    else
                    {
                        newMatch = new Match();

                        // Da unittesten ikke tager højde for random genererede kampe, kan dette ikke gøres
                        //int randomNumber1 = random.Next(tempTeams.Count);
                        //Team team1 = tempTeams[randomNumber1];
                        //tempTeams.RemoveAt(randomNumber1);

                        //int randomNumber2 = random.Next(tempTeams.Count);
                        //Team team2 = tempTeams[randomNumber2];
                        //tempTeams.RemoveAt(randomNumber2);

                        Team team1 = tempTeams[0];
                        tempTeams.RemoveAt(0);
                        Team team2 = tempTeams[0];
                        tempTeams.RemoveAt(0);

                        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);
                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();
            }
        }
Ejemplo n.º 2
0
        public void ScheduleNewRound(string tournamentName, bool printNewMatches = true)
        {
            Tournament t = tournamentRepository.GetTournament(tournamentName);
            int        numberOfRounds = t.GetNumberOfRounds();

            Round       lastRound;
            bool        isRoundFinished;
            List <Team> teams = new List <Team>();
            Team        oldFreeRider;
            Team        newFreeRider = null;
            List <Team> scramble;

            if (numberOfRounds == 0)
            {
                lastRound       = null;
                isRoundFinished = true;
            }
            else
            {
                lastRound       = t.GetRound(numberOfRounds - 1);
                isRoundFinished = lastRound.IsMatchesFinished();
            }
            if (isRoundFinished == true)
            {
                if (lastRound == null)
                {
                    teams = t.GetTeams();
                }
                else
                {
                    teams = lastRound.GetWinningTeams();
                    if (lastRound.FreeRider != null)
                    {
                        teams.Add(lastRound.FreeRider);
                    }
                }
                if (teams.Count > 1)
                {
                    scramble = teams.ToList();
                    Round newRound = new Round();

                    if (scramble.Count % 2 != 0)
                    {
                        if (numberOfRounds > 0)
                        {
                            oldFreeRider = lastRound.FreeRider;
                        }
                        else
                        {
                            oldFreeRider = null;
                        }

                        int x = 0;

                        while (newFreeRider == oldFreeRider)
                        {
                            newFreeRider = scramble[x];
                            x++;
                        }

                        newRound.FreeRider = newFreeRider;
                        scramble.Remove(newFreeRider);
                    }
                    for (int i = 0; i < scramble.Count; i = i + 2)
                    {
                        Match match = new Match();
                        match.FirstOpponent  = scramble[i];
                        match.SecondOpponent = scramble[i + 1];
                        newRound.AddMatch(match);
                    }
                    t.AddRound(newRound);
                    // Vis kampe i ny runde (se wireframe) Sprint 2 dag 1
                }
                else
                {
                    throw new Exception("Tournament is finished");
                }
            }
            else
            {
                throw new Exception("Round not finished");
            }
        }