private void SetWinnerToMatchup(Matchup match, Team winner)
        {
            if (winner == match.Team1)
            {
                match.Winner = match.Team1;
            }
            else
            {
                match.Winner = match.Team2;
            }

            //Check if this is the final
            if (match.Next == null)
            {
                string message = "CONGRATS TO ";

                if (match.Winner is Team2s)
                {
                    message += ((Team2s)match.Winner).Player1.Name;
                    message += " and " + ((Team2s)match.Winner).Player2.Name;
                }
                message += " FOR WINNING THE TOURNAMENT!!!!";
                MessageBox.Show(message, "TOURNEY WINNER", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
        private void Team2_Won(object sender, RoutedEventArgs e)
        {
            Matchup match = (Matchup)((Button)sender).DataContext;
            Team    t     = match.Team2;

            SetWinnerToMatchup(match, t);
            Close();
        }
Exemplo n.º 3
0
        private void SetWinner(object sender, RoutedEventArgs e)
        {
            Matchup            match = (Matchup)((MenuItem)sender).DataContext;
            WinnerSelectWindow win   = new WinnerSelectWindow();

            win.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            win.Title   = "Set Match Winner";
            win.Content = match;
            win.Show();
        }
Exemplo n.º 4
0
        public void GenerateMatchups(Matchup matchup, int round_num)
        {
            if (round_num < 0)
            {
                return;
            }

            //Generate 2 matchups per matchup

            Matchup m1 = new Matchup()
            {
                ID         = Matchups.Count,
                Team1      = null,
                Team2      = null,
                Winner     = null,
                Next       = matchup,
                IsFinished = false,
                RoundID    = round_num
            };

            Matchup m2 = new Matchup()
            {
                ID         = Matchups.Count + 1,
                Team1      = null,
                Team2      = null,
                Winner     = null,
                IsFinished = false,
                Next       = matchup,
                RoundID    = round_num
            };

            //Save Matchups
            Matchups.Add(m1);
            Matchups.Add(m2);

            //Add Matchups to round
            Rounds[round_num].Matchups.Add(m1);
            Rounds[round_num].Matchups.Add(m2);

            //Recursively generate previous rounds
            GenerateMatchups(m1, round_num - 1);
            GenerateMatchups(m2, round_num - 1);
        }
Exemplo n.º 5
0
        public void GenerateSVG()
        {
            SvgDocument doc = new SvgDocument();

            doc.FontSize = 16;

            SvgColourServer blackPainter = new SvgColourServer(Color.Black);
            SvgColourServer whitePainter = new SvgColourServer(Color.White);
            SvgColourServer grayPainter  = new SvgColourServer(Color.Gray);
            SvgColourServer greenPainter = new SvgColourServer(Color.LightGreen);


            int round_gap              = 50;
            int matchup_width          = 400;
            int matchup_height         = 150;
            int matchup_team_x_offset  = 20;
            int matchup_team_y_offset  = 50;
            int matchup_team_font_size = 36;
            int matchup_vs_font_size   = 24;

            int matchup_offset_y = 0;
            int matchup_gap_y    = 10;

            for (int r_i = 0; r_i < Rounds.Count; r_i++)
            {
                Round r = Rounds[r_i];
                Console.WriteLine("Round {0} Matches: ", r.ID);

                //Calculate matchup gap
                int round_x_offset = r_i * (matchup_width + round_gap);

                for (int m_i = 0; m_i < r.Matchups.Count; m_i++)
                {
                    Matchup m = r.Matchups[m_i];

                    int round_y_offset = m_i * (matchup_height + matchup_gap_y) + matchup_offset_y;

                    //Draw Rectangle per Matchup

                    SvgRectangle rec = new SvgRectangle();
                    rec.X      = round_x_offset;
                    rec.Y      = round_y_offset;
                    rec.Width  = matchup_width;
                    rec.Height = matchup_height;


                    if (!m.IsFinished)
                    {
                        rec.Fill = whitePainter;
                    }
                    else
                    {
                        rec.Fill = greenPainter;
                    }

                    doc.Children.Add(rec);

                    //Team 1 Text
                    string team_text = "TBD";
                    string team_id   = "";
                    if (m.Team1 != null)
                    {
                        if (m.Team1.IsDummy)
                        {
                            team_text = "-";
                        }
                        else
                        {
                            team_text = m.Team1.Name;
                            team_id   = m.Team1.ID.ToString("00");
                        }
                    }

                    //Add Text
                    //Τeam ID
                    SvgText t1 = new SvgText(team_id);
                    t1.FontSize = matchup_team_font_size;
                    t1.X.Add(round_x_offset + matchup_team_x_offset - 10);
                    t1.Y.Add(round_y_offset + matchup_team_y_offset);
                    doc.Children.Add(t1);

                    //Τeam Name
                    t1          = new SvgText(team_text);
                    t1.FontSize = matchup_team_font_size;
                    t1.X.Add(round_x_offset + 50 + matchup_team_x_offset);
                    t1.Y.Add(round_y_offset + matchup_team_y_offset);
                    doc.Children.Add(t1);

                    SvgText t3 = new SvgText("vs");
                    t3.FontSize = matchup_vs_font_size;
                    t3.X.Add(round_x_offset + matchup_team_x_offset);
                    t3.Y.Add(round_y_offset + 5 + matchup_height / 2.0f);
                    doc.Children.Add(t3);

                    //Horizontal Matchup Splitter Line Part 1
                    //Add horizontal line
                    SvgLine hl1 = new SvgLine();
                    hl1.Stroke        = blackPainter;
                    hl1.StrokeWidth   = 5;
                    hl1.StrokeOpacity = 1.0f;
                    hl1.FillOpacity   = 1.0f;
                    hl1.StartX        = round_x_offset + matchup_team_x_offset + 40;
                    hl1.StartY        = round_y_offset + matchup_height / 2.0f;
                    hl1.EndX          = round_x_offset + matchup_width;
                    hl1.EndY          = hl1.StartY;
                    doc.Children.Add(hl1);


                    //Vertical Line on the splitter
                    SvgLine vl1 = new SvgLine();
                    vl1.Stroke        = blackPainter;
                    vl1.StrokeWidth   = 5;
                    vl1.StrokeOpacity = 1.0f;
                    vl1.FillOpacity   = 1.0f;
                    vl1.StartX        = hl1.StartX;
                    vl1.StartY        = hl1.StartY;
                    vl1.EndX          = vl1.StartX;
                    vl1.EndY          = hl1.StartY - matchup_height / 2.0f;
                    doc.Children.Add(vl1);

                    SvgLine vl2 = new SvgLine();
                    vl2.Stroke        = blackPainter;
                    vl2.StrokeWidth   = 5;
                    vl2.StrokeOpacity = 1.0f;
                    vl2.FillOpacity   = 1.0f;
                    vl2.StartX        = hl1.StartX;
                    vl2.StartY        = hl1.StartY;
                    vl2.EndX          = vl1.StartX;
                    vl2.EndY          = hl1.StartY + matchup_height / 2.0f;
                    doc.Children.Add(vl2);


                    //Team 2 Text
                    team_text = "TBD";
                    team_id   = "";
                    if (m.Team2 != null)
                    {
                        if (m.Team2.IsDummy)
                        {
                            team_text = "-";
                        }
                        else
                        {
                            team_text = m.Team2.Name;
                            team_id   = m.Team2.ID.ToString("00");
                        }
                    }

                    //Τeam ID
                    SvgText t2 = new SvgText(team_id);
                    t2.FontSize = matchup_team_font_size;
                    t2.X.Add(round_x_offset + matchup_team_x_offset - 10);
                    t2.Y.Add(round_y_offset + matchup_height / 2.0f + matchup_team_y_offset);
                    doc.Children.Add(t2);

                    t2          = new SvgText(team_text);
                    t2.FontSize = matchup_team_font_size;
                    t2.X.Add(round_x_offset + 50 + matchup_team_x_offset);
                    t2.Y.Add(round_y_offset + matchup_height / 2.0f + matchup_team_y_offset);
                    doc.Children.Add(t2);

                    //Draw Matchup Connector to next Matchup
                    if (r_i != Rounds.Count - 1)
                    {
                        //Add horizontal line
                        SvgLine l = new SvgLine();
                        l.Stroke        = grayPainter;
                        l.StrokeWidth   = 5;
                        l.StrokeOpacity = 1.0f;
                        l.FillOpacity   = 1.0f;
                        l.StartX        = round_x_offset + matchup_width;
                        l.StartY        = round_y_offset + matchup_height / 2.0f;
                        l.EndX          = l.StartX + round_gap / 2.0f;
                        l.EndY          = l.StartY;
                        doc.Children.Add(l);

                        //Vertical Line
                        SvgLine l1 = new SvgLine();
                        l1.Stroke        = grayPainter;
                        l1.StrokeWidth   = 5;
                        l1.StrokeOpacity = 1.0f;
                        l1.FillOpacity   = 1.0f;
                        l1.StartX        = l.EndX;
                        l1.StartY        = l.EndY;
                        l1.EndX          = l.EndX;

                        if (m_i % 2 == 0)
                        {
                            l1.EndY = l.StartY + (matchup_height + matchup_gap_y) / 2.0f;
                        }
                        else
                        {
                            l1.EndY = l.StartY - (matchup_height + matchup_gap_y) / 2.0f;
                        }
                        doc.Children.Add(l1);

                        //Last horizontal line
                        SvgLine l2 = new SvgLine();
                        l2.Stroke        = grayPainter;
                        l2.StrokeWidth   = 5;
                        l2.StrokeOpacity = 1.0f;
                        l2.FillOpacity   = 1.0f;
                        l2.StartX        = l1.EndX;
                        l2.StartY        = l1.EndY;
                        l2.EndX          = l1.EndX + round_gap / 2.0f;
                        l2.EndY          = l1.EndY;
                        doc.Children.Add(l2);
                    }
                }

                //Update Matchup gaps and offsets
                matchup_offset_y += (matchup_height + matchup_gap_y) / 2;
                matchup_gap_y     = 2 * (matchup_gap_y + matchup_height) - matchup_height;
            }

            Bitmap img = doc.Draw();

            img.Save("bracket.png");
        }