Пример #1
0
        public void ScheduleNewRound(string tournamentName)
        {
            Tournament  selectedTournament = tournamentRepository.GetTournament(tournamentName);
            List <Team> teams     = null;
            Round       thisRound = null;

            //Get teams for new round
            int numberOfRounds = selectedTournament.GetNumberOfRounds();

            //Get teams for new round
            if (numberOfRounds == 0) //SPECIAL CASE: Initialize first round. Handled by adding all teams from tournament
            {
                teams = selectedTournament.Teams();
            }
            else // We are scheduling round > 0, get winners from this round if it is finished
            {
                thisRound = selectedTournament.GetRound(numberOfRounds);
                if (thisRound.IsRoundFinished())
                {
                    teams = thisRound.WinningTeams;
                    if (thisRound.FreeRider != null)
                    {
                        teams.Add(thisRound.FreeRider);
                    }
                }
                else
                {
                    throw new Exception("Round is not finished");
                }
            }

            if (teams.Count < 2)
            {
                selectedTournament.Status = Tournament.State.FINISHED;
            }
            else
            {
                Round newRound = new Round();

                //Manage freeRiders
                if ((teams.Count % 2) != 0) //Select a freeRider
                {
                    //If prior round exists and it had a freeRider and if was first team the select second team
                    if ((numberOfRounds > 0) && (thisRound.FreeRider != null) && (thisRound.FreeRider.Equals(teams[0])))
                    {
                        newRound.FreeRider = teams[1];
                        teams.Remove(teams[1]);
                    }
                    else //select first team
                    {
                        newRound.FreeRider = teams[0];
                        teams.Remove(teams[0]);
                    }
                }

                List <int> randomIndices = GetRandomIndices(teams.Count);
                int        noOfMatches   = teams.Count / 2;
                for (int i = 0; i < noOfMatches; i++)
                {
                    Match newMatch = new Match();
                    newMatch.FirstOpponent  = teams[randomIndices[2 * i]];
                    newMatch.SecondOpponent = teams[randomIndices[2 * i + 1]];
                    newRound.AddMatch(newMatch);
                }
                selectedTournament.AddRound(newRound);
                ShowRound(tournamentName, newRound, numberOfRounds);
            }
        }
Пример #2
0
 private void CreateTournament()
 {
     Tournament tournament = new Tournament(GetTournamentname());
 }
Пример #3
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();
            }
        }
Пример #4
0
        public void RegisterTournament(string name)
        {
            Tournament newTournament = new Tournament(name);

            RegisterTournament(newTournament);
        }
Пример #5
0
 public void RegisterTournament(Tournament tournament)
 {
     tournaments.Add(tournament);
 }
Пример #6
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");
            }
        }
Пример #7
0
        public void ShowScore(string tournamentName)
        {
            using (StreamWriter writer = new StreamWriter("C:/Users/woopi/Desktop/kode/Dragons-Lair-master/DragonsLair/TurneringResultat.txt"))
            {
                Tournament  tournament = tournamentRepository.GetTournament(tournamentName);  // Instancere et objekt kaldet tournament som referere til  metode i repo
                List <int>  points     = new int[tournament.GetTeams().Count].ToList <int>(); // Opretter en liste ud fra et tomt array som har længden af teams.
                List <Team> teams      = tournament.GetTeams();                               // Opretter en liste ved at kalde på metoden GetTeams fra tournament classen.

                int countedTeams = teams.Count;                                               // countedTeams tæller hvor mange teams der er i vores liste "teams"
                int rounds       = tournament.GetNumberOfRounds();                            // Tæller runder ved at kalde på metoden GetNumberOfRounds.

                for (int i = 0; i < rounds; i++)
                {
                    List <Team> winners = tournament.GetRound(i).GetWinningTeams(); // Liste med alle vinderne
                    if (winners[0] != null)                                         // hvis den første plads er null, betyder det at der ikke er nogle teams.
                    {
                        foreach (Team winner in winners)
                        {
                            for (int j = 0; j < tournament.GetTeams().Count; j++) // køre igennem så mange gange som der er hold.
                            {
                                if (winner.Name == tournament.GetTeams()[j].Name) // hvis holdet er vinderen, får de et point.
                                {
                                    points[j] = points[j] + 1;
                                }
                            }
                        }
                    }
                }

                Console.WriteLine("  #####                                        ");
                Console.WriteLine(" #     # ##### # #      #      # #    #  ####  ");
                Console.WriteLine(" #         #   # #      #      # ##   # #    # ");
                Console.WriteLine("  #####    #   # #      #      # # #  # #      ");
                Console.WriteLine("       #   #   # #      #      # #  # # #  ### ");
                Console.WriteLine(" #     #   #   # #      #      # #   ## #    # ");
                Console.WriteLine("  #####    #   # ###### ###### # #    #  ####  ");

                writer.WriteLine("  #####                                        ");
                writer.WriteLine(" #     # ##### # #      #      # #    #  ####  ");
                writer.WriteLine(" #         #   # #      #      # ##   # #    # ");
                writer.WriteLine("  #####    #   # #      #      # # #  # #      ");
                writer.WriteLine("       #   #   # #      #      # #  # # #  ### ");
                writer.WriteLine(" #     #   #   # #      #      # #   ## #    # ");
                writer.WriteLine("  #####    #   # ###### ###### # #    #  ####  ");

                Console.WriteLine("0-------------------------------------------0");
                writer.WriteLine("0-------------------------------------------0");
                Console.WriteLine("Turnering: " + tournamentName);
                writer.WriteLine("Turnering: " + tournamentName);
                Console.WriteLine("Spillede runder: " + rounds);
                writer.WriteLine("Spillede runder: " + rounds);
                writer.WriteLine("Vinder af turnering: ");
                Console.WriteLine("|----------------------------| VUNDNE KAMPE |");
                writer.WriteLine("|----------------------------| VUNDNE KAMPE |");
                for (int i = 0; i < countedTeams; i++)
                {
                    int index = points.IndexOf(points.Max());
                    Console.WriteLine(PaddedText(teams[index].ToString(), 27) + " - " + PaddedText(points[index].ToString(), 13));
                    writer.WriteLine(PaddedText(teams[index].ToString(), 27) + " - " + PaddedText(points[index].ToString(), 13));

                    points.RemoveAt(index);
                    teams.RemoveAt(index);
                }
                Console.WriteLine("0-------------------------------------------0");
                writer.WriteLine("0-------------------------------------------0");
                Console.ReadLine();
            }
        }
Пример #8
0
        public void ScheduleNewRound(string tournamentName, bool printNewMatches = true)
        {
            Tournament tournament = tournamentRepository.GetTournament(tournamentName);

            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();
            }
        }