This site requires JavaScript, please enable it in your browser!
Greenfoot back
Schoolboy123
Schoolboy123 wrote ...

2014/5/19

Connecting Pictures to Numbers

Schoolboy123 Schoolboy123

2014/5/19

#
Hey Guys. Some classmates and me have to create a game for school and we are kind of stuck at this point. We want to do a mastermind game and we want to create random numbers when we start the programm and each number should be connected to a picture. at the start of the game 4 random numbers should be created and then you can type in 4 colors into a field and itt should set the 4 colors as pictures on the screen and tell us if the pictures that should be connected to the numbers are equal to the numbers created in the beginning. our problem is that we cant connect the Numbers with the pictures and the strings for the colors. it would be nice if someone would be able to help us out. (:
danpost danpost

2014/5/19

#
Use an array of images.
1
public static GreenfootImage[] colorImage = new GreenfootImage[4];
or
1
2
3
4
5
6
public static GreenfootImage[] colorImage = {
    new GreenfootImage("image1.png"),
    new GreenfootImage("image2.png"),
    new GreenfootImage("image3.png"),
    new GreenfootImage("image4.png")
};
The index (number) refers to each image. There is no need to work with the strings for the colors.
You need to login to post a reply.