Hi, so I have this problem with my images that are arranged in this array. In my game, I have a correct door and a wrong door, in which when you click either of them the image will switch to the next set of "doors".
int set = 1
Here is the code for the CorrectDoor class:
The nextSet method is located in the GameWorld in which it should update the set number.
The two updateImage methods are located both in the CorrectDoor and the WrongDoor here, as well as the respective arrays that include the file names.
CorrectDoor
Wrong Door:
My problem is that when I click on the first set of doors, it skips the second set of doors for "3-correct.png" and "5-wrong.png", and also at the very end of these two arrays, when "89-correct.png" and "99-wrong.png", if you click on "89-correct.png", it only switches that individual door to "144.png" but not to the WrongDoor to "164.png"
I've had a look at these lines of code but I'm still not sure what the problem is ?
1 2 3 4 5 6 7 8 | public void act() { if (Greenfoot.mouseClicked( this )) { GameWorld world2 = (GameWorld) getWorld(); world2.nextSet(); } } |
1 2 3 4 5 6 | public void nextSet() { set++; door.updateImage(set); wrongdoor.updateImage(set); } |
1 2 3 4 5 6 7 8 | String [] cimages = { "3-correct.png" , "5-correct.png" , "8-correct.png" , "13-correct.png" , "21-correct.png" , "34-correct.png" , "55-correct.png" , "89-correct.png" , "144-correct.png" }; public void updateImage( int set) { setImage( new GreenfootImage(cimages[set - 1 ])); System.out.println(cimages[set]); } |
1 2 3 4 5 6 7 8 | String [ ] wimages = { "5-wrong.png" , "7-wrong.png" , "10-wrong.png" , "23-wrong.png" , "31-wrong.png" , "54-wrong.png" , "85-wrong.png" , "99-wrong.png" , "164-wrong.png" }; public void updateImage( int set) { setImage( new GreenfootImage(wimages[set - 1 ])); System.out.println(wimages[set]); } |