使用 C# 编写记忆游戏。所以我有一个包含 54 张图片的列表。我可以得到另一个列表来随机抓取其中的八张图像。然后,我想将第二个列表中的八张图片添加到另一个列表中,每张图片两次,很简单。
现在我想洗牌,我有点卡住了。我想随机播放列表的原因是因为我希望每次加载游戏(内存)或单击按钮(重新启动)时图片都是随机的......这是我对这个问题的看法:
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];
}