i am not sure if that helps, but I notice this:
step 1: you set all values in the index list of images to false, then clear to false to prevent of resetting it every frame.
step 2: if the mouse has been pressed, the next part gets the image fitting to your random index. then you set its index value to true (= it has already been shown)
step 3: next you iterate through the index list of booleans. if a value is not the same the value in the first one (…get(0)) you set clear to false. if their is an item that is not the same, set clear to true - effectively resetting the whole list.
step 4: if the selected item is already on true, make a new random value (find another image)
I believe there is something wrong with step 3
First of all, you always compare with the boolean at index 0.
If by chance the first randomValue is 0, the first image is displayed and set too true.
From that on, ALL other images will not fill the condition, so no more images can be selected. and the list will be reset.
Second you iterate through the whole list, setting clear again and again. So basically you ask if the value of the first item (0) is different only from the last items value.
Which can never happen (both are on false) unless you hit the first or the last item by chance.
If you do not hit that, the list is reset to all false again.
So only if the first randomValue found is the LAST item, it value will be != the first items value.
1st random Value = 0:
display the first image -> set its index value to true
boolean of image 0 equals itself -> clear = true -> all images are on false again
1st random Value = last image:
display the last image -> set its index value to true
boolean of last image does not equal image 0 -> chance to get another image by clicking
1st random Value = any image between first and last:
display that image -> set its index value to true
boolean of the last image equals first image -> clear = true -> all images are on false again
I think you should change your structure a little:
- all index values are false
- choose a random number
- if its value is true (literally -> if (cards.getValue(randomVal)) choose another randomValue or do nothing but wait for another click
- -> else, if its value is false -> display this image, set its value to true
- if there are no “false” values in the array (-> hasValue()) you are finished -> maybe now reset the list, so you can start again.
• i don’t think you need the clear variable. you could make a method to clear the list and call it whenever you need it. it does not have to be inside draw. same goes for your main loop, it could be another method that is called from within mousePressed.
• you could also have an IntList that has all the the indices of all your images. (0,1,2,3,4,5…)
whenever you generate a random value, you remove that item from the IntList leaving (0,1,2,4,5)
make the next randomValue up to the intList size.
so, first time the IntList hast the values (0,1,2) at the indices (0,1,2)
randomValue = (int(0,IntList.length) ->randomValue is 1 -> get its value (1) -> store it in a variable -> remove the entry
the list looks like this: values (0,2) at indices (0,1)
(int(0,IntList.length) -> … -> remove entry
hope this helps a little