We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello guys, I'm wondering why my shuffle method doesn't work. Im trying to shuffle my arraylist Arraylist <Card> cards = new Arraylist <Card>(8);
where I draw the images like
for (int y = 0; y < 3; y++){
for (int x = 0; x < 4; x++){
fv++;
if (fv==6){
fv=0;
}
cards.add( new Card (x*105+20, y*150+20, 105, 150, fv));
}
}
Collections.shuffle(cards);
I've imported the java.util.Collections but the images are always on the same place. Can you help me ? Thanks
(If you are wonderig what's the fv it's a face value)
Answers
It's pretty hard to study your code messed up like that. Please format it properly:
https://forum.Processing.org/two/discussion/8045/how-to-format-code-and-text
In a quick glance, I can't see anything wrong. Collections.shuffle() should simply work:
http://docs.Oracle.com/javase/8/docs/api/java/util/Collections.html#shuffle-java.util.List-
All you are doing is changing the order the cards are drawn because each cards position is fixed when it is created.
Oh now I get it I think. Do you think making a second arraylist where I put the images from the first would help? And if yes could you help me ? Thanks btw for the answer
I've got this example of a card deck. Maybe it can help ya: :)
https://forum.Processing.org/two/discussion/2801/picking-cards-at-random-then-excluding-those-from-further-picking
Yes create an arraylist of images
ArrayList <PImage> cardpics
then shuffle them withCollections.shuffle (cardpics);
then in draw you can display them with something like