vendredi 24 juillet 2015

Creating and accessing images using a for loop and if statements

Currently I am working on a simple children's counting game where you have to count the number of images shown on screen and pick the right answer to get points and win.

What I want is to be able to get a random image selected using a random number generator and depending on the number, get an image associated with it. So for this assignment I have made the image names to numbers and instead of using an if statement for all of them, I was hoping to use the number generated to be able to grab the image i wanted.

eg. int randomImage = random.Next(0,15); if the randomImage number is 6, it would pick the image named 6.png.

I was wondering if anybody knows of a way to do this. my attempt was along the lines of: pictureBox2.image = randomImage + ".png";

It might seem a little advanced but i hope somebody could help. Thank you very much




Aucun commentaire:

Enregistrer un commentaire