Mihaly Varga

Mihaly Varga

  • NA
  • 13
  • 8.5k

How to Shuffle a list in C#

Jan 7 2013 11:52 AM
So, this is my code:


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WindowsFormsApplication1;

public partial class Gyuru
{
    static Random random = new System.Random();
    private Graphics gr;
    private Bitmap bmp;
    private bool[,] EzCellak = new bool[5, 10];
    private System.Collections.Generic.List<Golyo> Golyok = new System.Collections.Generic.List<Golyo>();
    private System.Collections.Generic.List<bool[,]> EzSolutions = new System.Collections.Generic.List<bool[,]>();
    private bool EzUserPlay = false;
    private bool Playing = false;

    [System.ComponentModel.Browsable(false)]

    public bool[,] Cellak
    {
        get
        {
            return EzCellak;
        }
        set
        {
            EzCellak = value;
        }
    }

    public System.Collections.Generic.List<bool[,]> Solutions
    {
        get
        {
            return EzSolutions;
        }
        set
        {
            EzSolutions = value;
        }
    }

    public bool UserPlay
    {
        get
        {
            return EzUserPlay;
        }
        set
        {
            EzUserPlay = value;
        }
    }

    public Gyuru()
    {
        InitializeComponent();
        FeluletRajzol();
    }

    private void Gyuru_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
    {
        if (bmp != null)
        {
            this.BackgroundImage = bmp;
        }
    }

    private void Gyuru_Resize(object sender, System.EventArgs e)
    {
        if (bmp != null)
        {
            FeluletRajzol();
        }
    }

    public void FeluletRajzol()
    {
        if (this.Width > 0 && this.Height > 0)
        {
            bmp = new Bitmap(this.Width, this.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
            gr = Graphics.FromImage(bmp);
            System.Drawing.Drawing2D.LinearGradientBrush br = null;
            RectangleF rect = new RectangleF();

            //////////////////////////////////////////////////////////////////////


            for (byte i = 0; i <= 1; i++)
            {
                for (byte j = 0; j <= 9; j++)
                {
                    rect = new RectangleF((float)(j * System.Convert.ToSingle(bmp.Width / 8.0)), (float)(i * System.Convert.ToSingle(bmp.Height / 5.0) + 15), System.Convert.ToSingle(bmp.Width / 8.0), System.Convert.ToSingle(bmp.Height / 8.0));

                    br = new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);

                    gr.FillRectangle(br, rect);

                    Golyok.Add(new Golyo(i, j, "PIROS"));

                    gr.FillEllipse(new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.Red, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal), rect);

                }


            }


            for (byte i = 1; i <= 2; i++)
            {
                for (byte j = 0; j <= 9; j++)
                {
                    rect = new RectangleF((float)(j * System.Convert.ToSingle(bmp.Width / 8.0)), (float)(i * System.Convert.ToSingle(bmp.Height / 5.0) + 15), System.Convert.ToSingle(bmp.Width / 8.0), System.Convert.ToSingle(bmp.Height / 8.0));

                    br = new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);

                    gr.FillRectangle(br, rect);

                    Golyok.Add(new Golyo(i, j, "ZOLD"));

                    gr.FillEllipse(new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.Green, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal), rect);

                }


            }


            for (byte i = 2; i <= 3; i++)
            {
                for (byte j = 0; j <= 9; j++)
                {
                    rect = new RectangleF((float)(j * System.Convert.ToSingle(bmp.Width / 8.0)), (float)(i * System.Convert.ToSingle(bmp.Height / 5.0) + 15), System.Convert.ToSingle(bmp.Width / 8.0), System.Convert.ToSingle(bmp.Height / 8.0));

                    br = new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);

                    gr.FillRectangle(br, rect);

                    Golyok.Add(new Golyo(i, j, "SARGA"));

                    gr.FillEllipse(new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.Yellow, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal), rect);

                }


            }


            for (byte i = 3; i <= 4; i++)
            {
                for (byte j = 0; j <= 9; j++)
                {
                    rect = new RectangleF((float)(j * System.Convert.ToSingle(bmp.Width / 8.0)), (float)(i * System.Convert.ToSingle(bmp.Height / 5.0) + 15), System.Convert.ToSingle(bmp.Width / 8.0), System.Convert.ToSingle(bmp.Height / 8.0));

                    br = new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);

                    gr.FillRectangle(br, rect);

                    Golyok.Add(new Golyo(i, j, "KEK"));

                    gr.FillEllipse(new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.Blue, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal), rect);

                }


            }



            for (byte i = 4; i <= 5; i++)
            {
                for (byte j = 0; j <= 9; j++)
                {
                    rect = new RectangleF((float)(j * System.Convert.ToSingle(bmp.Width / 8.0)), (float)(i * System.Convert.ToSingle(bmp.Height / 5.0) + 15), System.Convert.ToSingle(bmp.Width / 8.0), System.Convert.ToSingle(bmp.Height / 8.0));

                    br = new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.White, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal);

                    gr.FillRectangle(br, rect);

                    Golyok.Add(new Golyo(i, j, "NARANCS"));

                    gr.FillEllipse(new System.Drawing.Drawing2D.LinearGradientBrush(rect, Color.Orange, Color.Black, System.Drawing.Drawing2D.LinearGradientMode.ForwardDiagonal), rect);

                }


            }





            //////////////////////////////////////////////////////////////////////



        }
    }


    

   
     
}









A picture: 

http://imageshack.us/photo/my-images/571/capturegld.png/


How could i shuffle the colors?