Advertisement

shuffle c#

Started by November 29, 2022 03:01 AM
1 comment, last by pbivens67 2 years ago

I am trying to shuffle values in a tic tac toe game.

            if (e.Button == MouseButtons.Right)
            {
                Graphics g = CreateGraphics();
                Font fnt = new Font("Verdana", 20);
                List<int> list = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
                var rnd = new Random();
                var randomized = list.OrderBy(item => rnd.Next());
                int num1 = randomized;
                {
                    if (num1 == 1)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 187, 112);
                    }
                    if (num1 == 2)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 245, 112);
                    }
                    if (num1 == 3)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 302, 112);
                    }
                    if (num1 == 4)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 187, 162);
                    }
                    if (num1 == 5)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 245, 162);
                    }
                    if (num1 == 6)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 302, 162);
                    }
                    if (num1 == 7)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 187, 212);
                    }
                    if (num1 == 8)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 245, 212);
                    }
                    if (num1 == 9)
                    {
                        g.DrawString("O", fnt, new SolidBrush(Color.Blue), 302, 212);
                    }
                }
            }
        }

the randomized value is where the error is

This topic is closed to new replies.

Advertisement