Skip to content

How can I write a c# program to draw a league table

theo philus

Asked Feb 14, 2009, 9:15 AM EST1 answer
Share
LinkedInX

  Can anyone help me with a c# program that can draw fixtures for  a league table for a soccer game with about 4 teams.

Please I want the source codes as well or send it to my email:

[email protected]

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Did you want a way of pairing up the teams? If so, i came up with this. I created a simple simple windows forms app with only a Button and TextBox control set to display as multiline. The button's click event runs the function CreateFixtures().
    I know more can be done to take the teams as teams names when the program runs and also the actual scheduling. I can add it later.

            private void CreateFixtures()
            {
                List<string> fixtures = new List<string>();
                string[] teams = { "A", "B", "C", "D" };
                foreach (string x in teams)
                    foreach (string y in teams)
                    {
                        if (x != y)
                        {
                            string teampair = MakePair(x, y);
                            if (!FixtureExists(x, y, fixtures))
                                fixtures.Add(teampair);
                        }
                    }
                PrintResults(fixtures);
            }
            private string MakePair(string teamx, string teamy)
            {
                return teamx + " - " + teamy;
            }
            private bool FixtureExists(string team1, string team2, List<string> lstFixtures)
            {
                bool isleftmatch = lstFixtures.Exists(delegate(string s) { return s == MakePair(team1, team2); });
                if (!isleftmatch)
                {
                    bool rightmatch = lstFixtures.Exists(delegate(string s) { return s == MakePair(team2, team1); });
                    isleftmatch = rightmatch;
                }
                return isleftmatch;
            }
            private void PrintResults(List<string> fixturelist)
            {
                StringBuilder strb = new StringBuilder();

                foreach(string s in fixturelist)
                {
                    strb.Append(s + "\r\n");
                }
                textBox1.Text = strb.ToString();
            }
    0