C# を使用してメモリ ゲームを記述します。だから私は54枚の画像のリストを持っています。別のリストを取得して、8 つの画像をランダムに取得できます。次に、2 番目のリストから別のリストに 8 つの画像を追加します。画像ごとに 2 回、簡単です。
今、リストをシャッフルしたいのですが、少し行き詰まっています。リストをシャッフルしたいのは、ゲーム(メモリ)がロードされるか、ボタン(再起動)がクリックされるたびに写真をランダムにしたいからです...これが私がこの問題のために持っているものです:
private void Form2_Load(object sender, EventArgs e)
{
//generate random number
Random r = new Random();
//play music via media player
axWindowsMediaPlayer1.uiMode = "none";
axWindowsMediaPlayer1.URL = ("Theme.mp3");
//create limage list
List<Image> imagesEasy;
//populate the 'imageEasy' list
imagesEasy = new List<Image>();
imagesEasy.Add(Image.FromFile(@"Baraka01.gif"));
imagesEasy.Add(Image.FromFile(@"Baraka02.gif"));
imagesEasy.Add(Image.FromFile(@"CyberSubZero01.gif"));
imagesEasy.Add(Image.FromFile(@"CyberSubZero02.gif"));
imagesEasy.Add(Image.FromFile(@"Cyrax01.gif"));
imagesEasy.Add(Image.FromFile(@"Cyrax02.gif"));
imagesEasy.Add(Image.FromFile(@"Ermac01.gif"));
imagesEasy.Add(Image.FromFile(@"Ermac02.gif"));
imagesEasy.Add(Image.FromFile(@"Jade01.gif"));
imagesEasy.Add(Image.FromFile(@"Jade02.gif"));
imagesEasy.Add(Image.FromFile(@"Jax01.gif"));
imagesEasy.Add(Image.FromFile(@"Jax01.gif"));
imagesEasy.Add(Image.FromFile(@"JohnnyCage01.gif"));
imagesEasy.Add(Image.FromFile(@"JohnnyCage02.gif"));
imagesEasy.Add(Image.FromFile(@"Kabal01.gif"));
imagesEasy.Add(Image.FromFile(@"Kabal02.gif"));
imagesEasy.Add(Image.FromFile(@"Kano01.gif"));
imagesEasy.Add(Image.FromFile(@"Kano02.gif"));
imagesEasy.Add(Image.FromFile(@"Katana01.gif"));
imagesEasy.Add(Image.FromFile(@"Katana02.gif"));
imagesEasy.Add(Image.FromFile(@"Kratos01.gif"));
imagesEasy.Add(Image.FromFile(@"Kratos02.gif"));
imagesEasy.Add(Image.FromFile(@"KungLau01.gif"));
imagesEasy.Add(Image.FromFile(@"KungLau02.gif"));
imagesEasy.Add(Image.FromFile(@"LiuKang01.gif"));
imagesEasy.Add(Image.FromFile(@"LiuKang02.gif"));
imagesEasy.Add(Image.FromFile(@"Mileena01.gif"));
imagesEasy.Add(Image.FromFile(@"Mileena02.gif"));
imagesEasy.Add(Image.FromFile(@"NightWolf01.gif"));
imagesEasy.Add(Image.FromFile(@"NightWolf02.gif"));
imagesEasy.Add(Image.FromFile(@"NoobSaibot01.gif"));
imagesEasy.Add(Image.FromFile(@"NoobSaibot02.gif"));
imagesEasy.Add(Image.FromFile(@"QuanChi01.gif"));
imagesEasy.Add(Image.FromFile(@"QuanChi01.gif"));
imagesEasy.Add(Image.FromFile(@"Raiden01.gif"));
imagesEasy.Add(Image.FromFile(@"Raiden02.gif"));
imagesEasy.Add(Image.FromFile(@"Scorpian01.gif"));
imagesEasy.Add(Image.FromFile(@"Scorpian02.gif"));
imagesEasy.Add(Image.FromFile(@"Sektor01.gif"));
imagesEasy.Add(Image.FromFile(@"Sektor02.gif"));
imagesEasy.Add(Image.FromFile(@"ShangTsung01.gif"));
imagesEasy.Add(Image.FromFile(@"ShangTsung02.gif"));
imagesEasy.Add(Image.FromFile(@"Sheeva01.gif"));
imagesEasy.Add(Image.FromFile(@"Sheeva02.gif"));
imagesEasy.Add(Image.FromFile(@"Sindel01.gif"));
imagesEasy.Add(Image.FromFile(@"Sindel02.gif"));
imagesEasy.Add(Image.FromFile(@"Smoke01.gif"));
imagesEasy.Add(Image.FromFile(@"Smoke02.gif"));
imagesEasy.Add(Image.FromFile(@"Sonya01.gif"));
imagesEasy.Add(Image.FromFile(@"Sonya02.gif"));
imagesEasy.Add(Image.FromFile(@"Stryker01.gif"));
imagesEasy.Add(Image.FromFile(@"Stryker02.gif"));
imagesEasy.Add(Image.FromFile(@"SubZero01.gif"));
imagesEasy.Add(Image.FromFile(@"SubZero02.gif"));
List<Image> imagesReady;
//populate the 'imageReady' list to fill remaining 8 pictureBoxes
imagesReady = new List<Image>();
imagesReady.Add(imagesEasy[r.Next(54)]);
imagesReady.Add(imagesEasy[r.Next(54)]);
imagesReady.Add(imagesEasy[r.Next(54)]);
imagesReady.Add(imagesEasy[r.Next(54)]);
imagesReady.Add(imagesEasy[r.Next(54)]);
imagesReady.Add(imagesEasy[r.Next(54)]);
imagesReady.Add(imagesEasy[r.Next(54)]);
imagesReady.Add(imagesEasy[r.Next(54)]);
List<Image> imagesFinal;
//populate the 'imageFinal' list to fill remaining 8 pictureBoxes
imagesFinal = new List<Image>();
imagesFinal.Add(imagesReady[0]);
imagesFinal.Add(imagesReady[1]);
imagesFinal.Add(imagesReady[2]);
imagesFinal.Add(imagesReady[3]);
imagesFinal.Add(imagesReady[4]);
imagesFinal.Add(imagesReady[5]);
imagesFinal.Add(imagesReady[6]);
imagesFinal.Add(imagesReady[7]);
imagesFinal.Add(imagesReady[0]);
imagesFinal.Add(imagesReady[1]);
imagesFinal.Add(imagesReady[2]);
imagesFinal.Add(imagesReady[3]);
imagesFinal.Add(imagesReady[4]);
imagesFinal.Add(imagesReady[5]);
imagesFinal.Add(imagesReady[6]);
imagesFinal.Add(imagesReady[7]);
//
//need to add or call shuffle method here before assigning pictures to pictureBoxes
//
//assign pictures to pictureBoxes from the imagesFinal list
pictureBox1.Image = imagesFinal[0];
pictureBox2.Image = imagesFinal[1];
pictureBox3.Image = imagesFinal[2];
pictureBox4.Image = imagesFinal[3];
pictureBox5.Image = imagesFinal[4];
pictureBox6.Image = imagesFinal[5];
pictureBox7.Image = imagesFinal[6];
pictureBox8.Image = imagesFinal[7];
pictureBox9.Image = imagesFinal[8];
pictureBox10.Image = imagesFinal[9];
pictureBox11.Image = imagesFinal[10];
pictureBox12.Image = imagesFinal[11];
pictureBox13.Image = imagesFinal[12];
pictureBox14.Image = imagesFinal[13];
pictureBox15.Image = imagesFinal[14];
pictureBox16.Image = imagesFinal[15];
}