Beispiel #1
0
        public string ShowScore(string tournamentName)
        {
            string Result = "";
            Dictionary <string, int> teamNameToScore = new Dictionary <string, int>();

            Tournament selectedTournament = tournamentRepository.GetTournament(tournamentName);
            int        numberOfRounds     = selectedTournament.GetNumberOfRounds();

            if (numberOfRounds > 0)
            {
                int numberOfMatches = 0;
                for (int i = 1; i <= numberOfRounds; i++)
                {
                    Round currentRound = selectedTournament.GetRound(i);
                    numberOfMatches = numberOfMatches + currentRound.GetNumberOfMatches();
                    foreach (Team winningTeam in currentRound.WinningTeams)
                    {
                        if (!teamNameToScore.ContainsKey(winningTeam.Name))
                        {
                            teamNameToScore.Add(winningTeam.Name, 0);
                        }
                        teamNameToScore[winningTeam.Name] = teamNameToScore[winningTeam.Name] + 1;
                    }
                }

                //output in sorted order starting with highest score - find highest score
                int highestScore = GetHighestScore(teamNameToScore);

                PrintHeader();
                Result += ($"|      Liga : {tournamentName}                     |\n");
                Result += ($"|      Spillede runder : {numberOfRounds}                         |\n");
                Result += ($"|      Spillede kampe : {numberOfMatches}                         |\n");
                Result += ("-----------------------------------| Vundne kampe  |\n");

                for (int i = highestScore; i >= 0; i--)
                {
                    foreach (KeyValuePair <string, int> element in teamNameToScore)
                    {
                        if (element.Value == i)
                        {
                            int    score = highestScore - i + 1;
                            string name  = PadSpaceToName(element.Key, 18);
                            Console.WriteLine($"|         {score}. {name}    |      {element.Value}        |");
                        }
                    }
                }
                PrintFooter();
            }
            return(Result);
        }
Beispiel #2
0
        public void ShowScore(string tournamentName)
        {
            Dictionary <string, int> teamNameToScore = new Dictionary <string, int>();

            Tournament selectedTournament = tournamentRepository.GetTournament(tournamentName);
            int        numberOfRounds     = selectedTournament.GetNumberOfRounds();

            if (numberOfRounds > 0)
            {
                int numberOfMatches = 0;
                for (int i = 1; i <= numberOfRounds; i++)
                {
                    Round currentRound = selectedTournament.GetRound(i);
                    numberOfMatches = numberOfMatches + currentRound.GetNumberOfMatches();
                    foreach (Team winningTeam in currentRound.WinningTeams)
                    {
                        if (!teamNameToScore.ContainsKey(winningTeam.Name))
                        {
                            teamNameToScore.Add(winningTeam.Name, 0);
                        }
                        teamNameToScore[winningTeam.Name] = teamNameToScore[winningTeam.Name] + 1;
                    }
                }

                //output in sorted order starting with highest score - find highest score
                int highestScore = GetHighestScore(teamNameToScore);


                this.TournamentName = tournamentName;
                this.Round          = numberOfRounds;
                this.PlayedMatch    = numberOfMatches;

                string score1 = null;

                for (int i = highestScore; i >= 0; i--)
                {
                    foreach (KeyValuePair <string, int> element in teamNameToScore)
                    {
                        if (element.Value == i)
                        {
                            int    score = highestScore - i + 1;
                            string name  = PadSpaceToName(element.Key, 18);
                            score1 += ($"   {score} {name}  {element.Value}\n");
                        }
                    }
                }
                ScoreString = score1;
            }
        }