I'm trying to create matching game. This game consist of three picture boxes where each picture boxes shows random images that changes 3 times within a second. The objective of this game is to match all images in each picture box to beat the game.
This code is somewhat working. It is running but I cannot get the speed setting to work. It is currently just running 1 image per second. The ChangeImage() is turned off at the moment since I cannot get it to work. Please excuse my explanation.
To start off, I created a list of images where my pictures are added:
private List<Bitmap> paths = new List<Bitmap>();
public Form1()
{
InitializeComponent();
paths.Add(Properties.Resources.Pumpkin);
paths.Add(Properties.Resources.Cherry);
paths.Add(Properties.Resources.Pineapple);
paths.Add(Properties.Resources.Apples);
}
I also have an event handler to produce the random image in a picture box:
private void timer2_Tick(object sender, EventArgs e)
{
picBox2.Image = paths[randomImg2.Next(0, paths.Count)];
}
and to start the game, I have another even handler that allow the player to select the speed of the images' cycle:
private void btnPlay_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
if (radThreeSpeed.Checked)
{
ChangeImage(3);
}
if (radFiveSpeed.Checked)
{
ChangeImage(5);
}
}
private void ChangeImage(int loop)
{
int imageCount = 1;
while (imageCount <= loop)
{
picBox1.Image = paths[randomImg1.Next(0, paths.Count)];
imageCount++;
}
}
My question is, how can I get this to work so that the image changes 3x or 5x or however I would like it to be within a second?
Aucun commentaire:
Enregistrer un commentaire