All pastes #959546 Raw Edit

Untitled

public text v1 · immutable
#959546 ·published 2008-03-27 15:00 UTC
rendered paste body
private void button1_Click(object sender, EventArgs e)
        {
            string[] teams = textBox1.Text.Split('\n');
            Stack<string> teams_stack = new Stack<string>();
            for (int x = 0; x < teams.Length; x++)
                teams_stack.Push(teams[x]);
            int counter = teams.Length / 2;
            string mem = "";
            while (counter > 0)
            {
                RandomNumbers nums = Random_num(teams_stack.Count + 1);
                Games game = new Games();
                game.SetHome(GetTeamName(teams_stack, nums.GetNum1()));
                game.SetAway(GetTeamName(teams_stack, nums.GetNum2()));
                PopPlaces(teams_stack, nums);
                counter++;
                mem += game.ToString();
            }
            mem.Remove(mem.Length - 1, 1);
            textBox1.Text = mem;
        }
        private RandomNumbers Random_num(int num)
        {
            Random rand = new Random();
            int num1, num2;
            num1 = rand.Next(1, num);
            do
            {
                num2 = rand.Next(1, num);
            }
            while (num2 == num1);
            RandomNumbers nums = new RandomNumbers(num1, num2);
            return nums;
        }
        private string GetTeamName(Stack<string> teams_stack, int place)
        {
            int counter = 0;
            Stack<string> st = new Stack<string>();
            while (counter != place)
            {
                st.Push(teams_stack.Pop());
                counter++;
            }
            string returnValue = st.Peek();
            while (st.Count > 0)
                teams_stack.Push(st.Pop());
            return returnValue;
        }
        private void PopPlaces(Stack<string> st, RandomNumbers nums)
        {
            if (nums.GetNum1() > nums.GetNum2())
            {
                Poper(st, nums.GetNum1());
                Poper(st, nums.GetNum2());
            }
            else
            {
                Poper(st, nums.GetNum2());
                Poper(st, nums.GetNum1());
            }
        }
        private void Poper(Stack<string> st, int num)
        {
            int counter = 0;
            Stack<string> st1 = new Stack<string>();
            while (counter != num)
            {
                st1.Push(st.Pop());
                counter++;
            }
            st1.Pop();
            while (st1.Count > 0)
                st.Push(st1.Pop());
        }