Exemplo n.º 1
0
 private void StartButton_Click(object sender, RoutedEventArgs e)
 {
     if (NavigationService != null)
     {
         NavigationService.Navigate(new RoundPage(RoundGenerator.Next(Quiz.Participants)));
     }
 }
            public static Fixture GenerateFixture()
            {
                Fixture         fixture         = new Fixture();
                PossibleMatches possibleMatches = new PossibleMatches();

                Round firstRound = RoundGenerator.GenerateRound();

                fixture.Rounds.Add(firstRound);
                PrintRound(fixture, firstRound);


                foreach (Match m in firstRound.Matches)
                {
                    possibleMatches.Matches.Remove(m);
                }

                int attemptsToGenerateRound = 0;

                while (fixture.Rounds.Count < MAX_ROUNDS)
                {
                    Round possibleRound = RoundGenerator.GenerateRound();

                    if (!fixture.ContainsRound(possibleRound))
                    {
                        attemptsToGenerateRound = 0;
                        fixture.Rounds.Add(possibleRound);
                        PrintRound(fixture, possibleRound);
                        foreach (Match m in possibleRound.Matches)
                        {
                            possibleMatches.Matches.Remove(m);
                        }
                    }
                    else
                    {
                        attemptsToGenerateRound++;
                        if (attemptsToGenerateRound > 1000)
                        {
                            Round remainingRound = RoundGenerator.GenerateRoundFromList(possibleMatches.Matches);
                            fixture.Rounds.Add(remainingRound);
                            PrintRound(fixture, remainingRound, true);
                            attemptsToGenerateRound = 0;
                        }
                    }
                }
                RoundGenerator.CleanList();

                if (!fixture.IsValid())
                {
                    PrintInvalidFixtureMessage();
                }

                return(fixture);
            }
Exemplo n.º 3
0
        private void NextRoundButton_Click(object sender, RoutedEventArgs e)
        {
            Page nextPage = null;
            List <Participant> correctParticipants = Round.ParticipantAnswers.Where(a => a.WasCorrect ?? false).Select(a => a.Participant).ToList();

            if (correctParticipants.Count == 1 && !Round.Question.TestQuestion)
            {
                nextPage = new WinnerPage(correctParticipants[0]);
            }
            else
            {
                List <Participant> participantsToCarryOver = correctParticipants;
                if (correctParticipants.Count == 0 || Round.Question.TestQuestion)
                {
                    participantsToCarryOver = Round.ParticipantAnswers.Select(a => a.Participant).ToList();
                }
                nextPage = new RoundPage(RoundGenerator.Next(participantsToCarryOver));
            }
            if (NavigationService != null)
            {
                NavigationService.Navigate(nextPage);
            }
        }
Exemplo n.º 4
0
        public static List <Fixture> CreateRandomFixtures(List <Team> teams, bool isTwoLeggedTie)
        {
            // *************************************************
            // TODO: Create it for DATES, COURT
            // Round: problema com impar
            // *************************************************
            var fixtures = new List <Fixture>();
            var rounds   = new RoundGenerator(teams);

            if (teams != null && teams.Count > 1)
            {
                Shuffle(teams);

                for (var i = 0; i < teams.Count; i++)
                {
                    var home  = true;
                    var team1 = teams[i];
                    for (var j = i + 1; j < teams.Count; j++)
                    {
                        var team2 = teams[j];

                        var fixture = new Fixture();
                        if (home)
                        {
                            fixture.TeamHome    = team1;
                            fixture.TeamVisitor = team2;
                        }
                        else
                        {
                            fixture.TeamHome    = team2;
                            fixture.TeamVisitor = team1;
                        }
                        fixture.Status = FixtureStatus.Pending;
                        fixture.Round  = rounds.GetRoundByTeam(team1, team2);
                        fixture.Leg    = 1;
                        //fixture.Date
                        //fixture.Court

                        fixtures.Add(fixture);
                        home = !home;
                    }
                }

                if (isTwoLeggedTie)
                {
                    var fixtureCount = fixtures.Count;
                    for (int i = 0; i < fixtureCount; i++)
                    {
                        var newFixture = CloneObject(fixtures[i]);
                        newFixture.Id  = Guid.NewGuid();
                        newFixture.Leg = 2;
                        var teamHome    = newFixture.TeamVisitor;
                        var teamVisitor = newFixture.TeamHome;
                        newFixture.TeamHome    = teamHome;
                        newFixture.TeamVisitor = teamVisitor;
                        fixtures.Add(newFixture);
                    }
                }
            }

            GuaranteeUniqueId(fixtures);
            return(fixtures.GroupBy(g => g.Leg).OrderBy(g => g.Key).SelectMany(g => g.OrderBy(x => x.Round)).ToList());
        }