Ejemplo n.º 1
0
        private async void btnMatch_Click(object sender, RoutedEventArgs e)
        {
            if (finals)
            {
                String winner;
                if (bracket.Matches[bracket.Matches.Count - 1].Club1Goals > 
                    bracket.Matches[bracket.Matches.Count - 1].Club2Goals)
                {
                    winner = bracket.Matches[bracket.Matches.Count - 1].club1;
                }
                else { winner = bracket.Matches[bracket.Matches.Count - 1].club2; }

                var md = new MessageDialog(winner + " are champions!");

                md.Commands.Add(new UICommand("Exit", (UICommandInvokedHandler) =>
                {
                    App.Current.Exit();
                }));
                
                await md.ShowAsync();
            }

            if (bracket.CurrentMatch < bracket.MatchCount - 1 && !swapped)
            {

                UpdatePlayerStats();
                MatchList.Items.RemoveAt(0);

                bracket.CurrentMatch++;
                if (bracket.CurrentMatch == bracket.MatchCount - 1)
                {
                    btn_Match.Content = "End match";
                }

            }
            else if (MatchList.Items.Count > 0 && !swapped)
            {
                UpdatePlayerStats();
                MatchList.Items.RemoveAt(0);
                bracket.CurrentMatch++;
                
                //Final
                List<Player> temp = new List<Player>();
                temp.Add(bracket.Players[0]);
                temp.Add(bracket.Players[1]);
                if (bracket.Players[1].Points == bracket.Players[2].Points)
                {
                    temp.Add(bracket.Players[2]);
                    if (temp[0].Points == temp[2].Points)
                    {
                        temp.Sort(delegate(Player p1, Player p2)
                        { return p2.GoalDifference.CompareTo(p1.GoalDifference); });
                    }
                }
                
                bracket.Matches.Add(new Match(temp[0], temp[1]));
                txbMatches.Text = "League final!";

                ListViewItem lwi = new ListViewItem();
                lwi.FontFamily = font;
                lwi.Content = bracket.Matches[bracket.Matches.Count - 1].ToString();
                MatchList.Items.Clear();
                MatchList.Items.Add(lwi);
                finals = true;

            }
        }